# -----------------------------------------
# SIMPLE LISP QUESTION ANSWER PROGRAM...
#
# AUTHOR: MATTHEW WILLIAM COAN
# DATE: SEP. 6, 2019 08:39PM
# -----------------------------------------

(set question-list (make-list))
(set question-map (make-map))
(set visited-map (make-map))

(defun ask (answer) 
   (set question (cons (list 'who 'is answer)))
   (cond (= nil (map-get visited-map question)) (
      (map-put visited-map question 'TRUE)
      (t (append question-list question))
   ))
   (set question (cons (list 'what 'is answer)))
   (cond (= nil (map-get visited-map question)) (
      (map-put visited-map question 'TRUE)
      (t (append question-list question))
   ))
   (set question (cons (list 'when 'is answer)))
   (cond (= nil (map-get visited-map question)) (
      (map-put visited-map question 'TRUE)
      (t (append question-list question))
   ))
   (set question (cons (list 'where 'is answer)))
   (cond (= nil (map-get visited-map question)) (
      (map-put visited-map question 'TRUE)
      (t (append question-list question))
   ))
   (set question (cons (list 'why 'is answer)))
   (cond (= nil (map-get visited-map question)) (
      (map-put visited-map question 'TRUE)
      (t (append question-list question))
   ))
   (set question (cons (list 'how 'is answer)))
   (cond (= nil (map-get visited-map question)) (
      (map-put visited-map question 'TRUE)
      (t (append question-list question))
   ))
)

(defun ask-user (question) 
   (print question)
   (print "\n")
   (print "answer> ")
   (set answer (input))
   (t (map-put question-map question answer))
   (ask answer)
)

(defun tag-text (text)
   (return nil)
)

(defun convert (english)
   (return nil)
)

(defun auto-answer (question)
   (map-get question-map question)
#   (set answer (map-get question-map question))
#   (cond (= nil answer) (
#      (set english (tag-text question))
#      (set code (convert english))
#      (cond (= nil code) (
#         (set answer (eval code))
#         (map-put question-map question answer)
#      ))
#   ))
)

(defun question-loop (question) 
   (cond (= nil (auto-answer question)) (
      (ask-user question))
   (
      (print question)
      (print "\n")
      (set answer (map-get question-map question))
      (print answer)
      (print "\n")
      (ask answer)
   ))
   (cond (<> 0 (length question-list)) (
      (set q (car question-list))
      (set question-list (cdr question-list))
      (question-loop q)
   ))
)

(defun ai-main () 
   (print "question> ")
   (set question (input))
   (cond (find question "quit") (
      (question-loop question)
      (map-clear visited-map)
      (ai-main)
   ))
)

(print "LISP Artificial Intelligence 1.0\n")
(print "Program auther: Matthew W. Coan\n")
(print "Email: matthewcoan1976@hotmail.com\n\n")
(print "Please type \"quit\" to end this program...\n\n")

(ai-main)

