2013-02-13 54 views
2

我正在學習Scheme並使用一些示例來查看工作內容。計劃中的SHOW/READ/READ-LINE/etc程序

我正在Eclipse中使用Chicken解釋器。

當試圖運行下面的代碼:

(define (bottles n) 
    (if (= n 0) 
     'burp 
     (begin (verse n) 
     (bottles (- n 1))))) 

(define (verse n) 
    (show (cons n '(bottles of beer on the wall))) 
    (show (cons n '(bottles of beer))) 
    (show '(if one of those bottles should happen to fall)) 
    (show (cons (- n 1) '(bottles of beer on the wall))) 
    (show '())) 

(bottles 3) 

而且我收到以下錯誤:

#;1> #;2> Note: the following toplevel variables are referenced but unbound: 

    verse (in bottles) 
#;3> #;3> Note: the following toplevel variables are referenced but unbound: 

    show (in verse) show (in verse) show (in verse) show (in verse) show (in verse) 

Error: unbound variable: show 

Call history: 

<syntax>  (bottles 3) <eval> (bottles 3) <eval> [bottles] (= n 0)  <eval> [bottles] (verse n) <eval> [verse] (show (cons n (quote (bottles of beer on the wall)))) <-- 

有誰知道這是爲什麼?當然,如果我創建一個說明「show」將會顯示內容的程序,那麼它就可以工作,但是應該將SHOW作爲Scheme的標準程序嗎?因爲許多通過互聯網節目的代碼是這樣的,沒有「顯示」程序說明。 READ/READ-LINE等發生同樣的事情。

謝謝!

+0

我真的不進的小寵物^ W方案,但它'display',而不是'show'? – 2013-02-13 19:58:00

+0

不,我從這裏得到了這個例子:http://www.eecs.berkeley.edu/~bh/ssch20/io.html – user1060551 2013-02-13 20:09:58

+2

該章引述:「事實上,show不是官方的Scheme原語,我們根據顯示和換行編寫了它。「 – 2013-02-13 20:12:55

回答

5

show程序未定義。作爲Chicken計劃中實施的R5RS的一部分,您可以使用displaywrite進行輸出,如documentation中所示。

show的功能可以輕鬆實現,但:

(define (show obj) 
    (display obj) 
    (newline)) 
+0

什麼是最完整的Scheme解釋器? – user1060551 2013-02-13 21:04:12

+0

@ user1060551這是一個非常非常主觀的問題,它取決於你對「完整」的理解。爲了學習的目的,我喜歡DrRacket。 – 2013-02-13 21:05:42

0

雞對show名字是print。 如果 (define show print) 您可以使用名稱