;;TODO: Implement a new package for the programm (defvar *user-says*) (defvar *user-line*) (defvar *mylist*) ;; the cl-perl library, has to be in the same folder as the programm, ;;or somewhere lisp finds it (require 'cl-ppcre) (defvar *possible-answers* '(("hello" "hello" "hiz!!" "hey, hello") ("really" "yes" "no, was just kidding" "why don't you believe me?") ("why" "because" "What do you mean why?") ("yes" "Are you sure?" "Why yes?") ("no" "Why not?" "Why no" "You seem to be a bit negative...") ("place-keeper" "What makes you say that?" "why is that" "Do you really mean that?" "I don't believe a word"))) (defun prompt-read (prompt) "A function to communicate with the user" (format *query-io* "~a~%" prompt) (force-output *query-io*) (read-line *query-io*)) (defun start () "The main programm. It gets a phrase from the user, and writes a response" (setf *user-says* (prompt-read "Welcome...")) (loop (setf *user-line* (select-a-line *user-says*)) (setf *user-says* (prompt-read (elt (cdr *user-line*) (random (length (cdr *user-line*)))))))) (defun select-a-line (phrase) "Select the line from the *possible-answers* alist that has a word from the phrase. If no word matches, get the last line with the defaults" (setf *mylist* (extract-words phrase)) (or (loop for j in *possible-answers* do (if (find (first j) *mylist* :test #'string=) (return j))) (elt *possible-answers* (- (length *possible-answers*) 1)))) (defun extract-words (text) "To extract words from the phrase. I use a library that allows me to run perl commands inside from lisp" (delete-duplicates (cl-ppcre:all-matches-as-strings "[a-zA-Z]{3,}" text) :test #'string=))