; Eliza: classic therapeutic program ; type (run) to run ; ; Example conversation: ; (I love dogs) ; (tell me why you love dogs ?) ; (they are so cute) ; (do you regularly show your affection ?) ; (yes, i hate my brother) ; (tell me more about your brother) ; (he is mean to me) ; That is interesting. Go on please. ; (what do you want to hear from me?) ; (this is about you, not me) (define run (lambda () (display "Welcome. Tell me something about you so I can get to know you better.") (newline) (loop) ) ) (define loop (lambda () (reply (read)) (loop) ) ) (define reply (lambda (in) (cond ((match1 'my in '(Tell me more about your x))) ((match1 'his in '(What about his x ?))) ((match1 'her in '(What about her x ?))) ((match0 'you in '(This is about you, not me))) ((match1 'love in '(Tell me why you love x ?))) ((match1 'hate in '(What is your problem with x ?))) ((match0 'brother in '(Tell me more about your brother))) ((match0 'sister in '(Tell me more about your sister))) ((match0 'wondering in '(What caused this uncertainty ?))) ((match0 'cute in '(Do you regularly show your affection ?))) ((match0 'love in '(You like that ?))) (else (continue)) ) ) ) (define match0 (lambda (pattern in out) (let ((lst (memv pattern in))) (cond ((null? lst) #f) (else (begin (display out) (newline) #t ) ) ) ) ) ) (define match1 (lambda (pattern in out) (let ((lst (memv pattern in))) (cond ((null? lst) #f) ((null? (cdr lst)) #f) (else (begin (display (insert (car (cdr lst)) out)) (newline) #t ) ) ) ) ) ) (define insert (lambda (elt lst) (if (eq? (car lst) 'x) (cons elt (cdr lst)) (cons (car lst) (insert elt (cdr lst))) ) ) ) (define continue (lambda () (display "That is interesting. Go on please.") (newline) ) )