; Start the program up by printing a welcome and ; returning the result of a visit with the doctor ; starting with an empty history (since nothing has happened yet). (define (doctor) (show "please type all your input within parentheses.") (show "") ; print a carriage return (show "Type (goodbye) to end the session.") (visit-with-doctor '()) ) ; Return the result of a visit with the doctor. ; The history variable tells us some information about stuff ; the user has previously typed. ; All we do is print a prompt, read a list from the user ; (she has to parenthesize the input), compute a response, and ; return the result of subsequent interaction with the doctor. ; The response will have two parts: our actual reply to the ; user is the car, and the updated history is the cdr. ; This version of the program doesnąt collect a history. (define (visit-with-doctor history) (show "") (display "** ") (let ((patient-says (read))) ; gets a list typed by the user (cond ((equal? (car patient-says) 'goodbye) '(your bill will be in the mail) ) (else (let ((we-say (response patient-says history))) (show (car we-say)) (visit-with-doctor (cdr we-say)) ) ) ) ) ) ; Return a response to a sentence the patient has typed. ; The argument history represents a history of the dialog between us ; and the patient. ; Our response is a pair consisting of what we say to the patient (the car) and ; the updated history (the cdr). ; Note in this version we don't change the history, ; and we merely parrot back what the user said. (define (response sentence history) (cons sentence history) )