以下代码出错

时间:2013-02-28 04:12:09

标签: scheme racket

当我这样做时(访问医生超时):

(define (visit-doctor name)
  (if (equal? name 'suppertime) (end-session)
  ((write-line (list 'hello name))
  (write-line '(what seems to be the trouble?))
  (doctor-driver-loop name initial-earlier-response))))

(define (end-session) (write-line '(the doctor is done seeing patients today)))

它给了我这个错误:

申请:不是程序;  期望一个可以应用于参数的过程   给出:#   参数...:    #    #

1 个答案:

答案 0 :(得分:3)

您的问题是您尝试使用括号分组代码块 Scheme不会这样做。

您的else分支

((write-line (list 'hello name))
 (write-line '(what seems to be the trouble?))
 (doctor-driver-loop name initial-earlier-response))

这是三个元素的列表。

该列表的第一个元素应该是一个过程,然后应用于其他两个元素,但是当您评估(write-line (list 'hello name))时没有得到过程时,您会得到#<void>

修复方法是使用begin对其进行排序:

(begin (write-line (list 'hello name))
       (write-line '(what seems to be the trouble?))
       (doctor-driver-loop name initial-earlier-response))