use*_*551 2 lisp scheme procedure
我正在学习Scheme并使用一些例子来看看这些东西在起作用.
我正在使用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"会显示东西的程序,那么它可以工作,但是应该显示一个来自Scheme的标准程序吗?因为许多代码通过互联网显示,并且没有"显示"程序描述.同样的事情发生在READ/READ-LINE等.
谢谢!
该show过程未定义.作为鸡计划中实施的R5RS的一部分,您可以使用display或write输出,如文档中所示.
但是,功能show很容易实现:
(define (show obj)
  (display obj)
  (newline))