2013-02-28 60 views
0

當我做(造訪醫生吃晚飯),此代碼:錯誤與下面的代碼

(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))) 

它給了我這個錯誤:

應用程序:不是一個程序; 預期考慮到可以應用到參數的過程 :# 參數...: # #

+0

如果使用DrRacket,你看到了相應於球拍認爲錯誤可能位於一個紅色的亮點?我在行上看到一個問題'((write-line(list'hello name)):對我來說,它看起來像一個雙功能應用程序,你可能打算做一個單一的應用程序,對於這個特定的情況,DrRacket **應該**給你這個錯誤的確切位置,你看到了嗎? – dyoo 2013-02-28 07:49:28

回答

3

你的問題是,你正在嘗試使用括號進行分組的代碼塊。
計劃沒有這樣做。

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))