Racket(Scheme)错误:预期引用后的符号名称,但找到了一个部分

Kri*_*mar 2 scheme the-little-schemer racket

我在Dr. Racket Verion 5.3.6中运行此代码(The Little Schemer):

(define rember
(lambda (a lat)
(cond
  ((null? lat) (quote ()))
  (else 
   (cond
     ((eq? (car lat) a) (cdr lat))
     (else (cons (car lat) (rember a (cdr lat)))))))))
Run Code Online (Sandbox Code Playgroud)

并引发错误:quote: expected the name of the symbol after the quote, but found a part(quote ()))一部分.我在这做错了什么?

soe*_*ard 5

该错误表示您选择以"Beginning Student"语言运行该程序.在这种语言中,表格quote受到限制.

如果您将语言更改为"使用列表缩写开始学生",一切都会顺利进行.

让我们quote在"初学者"语言的文档中查找:

quote初学者中的表格

您将看到语法被描述为(syntax name).如果将此与"使用列表缩写开始学生"的文档进行比较,您quote现在可以引用列表.

Beginning Student语言受限制的原因是只有表格(quote name)在HtDP的开头使用,所以如果跟随HtDP的学生写的'(foo bar)则不是故意的.因此,错误(声明名称是预期的)是有帮助的 - 因此quote需要限制表单.