我正在尝试编写一个程序,其中医生只看到 5 名患者,然后程序结束。现在它还没有结束,它一直在寻找下一个病人。忽略医生驱动循环过程中的 else。我在该过程中添加了一个计数,但我想它每次都会回到零。我该如何解决?
(define count 0)
(define (new-patient counter)
(if (= counter 5) (write-line 'doctor has seen 5 patients today so the day is now over)
(visit-doctor (ask-patient-name))))
(define (doctor-driver-loop name earlier-responses)
(newline)
(write '**)
(let ((user-response (read)))
(cond ((equal? user-response '(goodbye))
(write-line (list 'goodbye name))
(write-line '(see you next week))
(new-patient (+ 1 count)))
(else (write-line (reply (responses-list earlier-responses user-response) user-response))
(doctor-driver-loop name (responses-list earlier-responses user-response))))))
(define (visit-doctor name)
(write-line (list 'hello name))
(write-line '(what seems to be the trouble?))
(doctor-driver-loop name initial-earlier-response))