【发布时间】:2022-01-07 18:02:42
【问题描述】:
在以下方案代码中,accumulate 进行右折叠。当我尝试使用 mit 方案运行时。我遇到了以下错误:
Transformer may not be used as an expression: #[classifier-item 13]
Classifier may not be used as an expression: #[classifier-item 12]
我用谷歌搜索但没有找到有用的信息。和宏有关吗?
; This function is copied from SICP chapter 2
(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))
; works as expected
(accumulate
(lambda (x y) (or x y)) ; replace or with and also works
#f
'(#t #f #t #f #f)
))
; does not work
; error: Classifier may not be used as an expression: #[classifier-item 12]
(accumulate
or
#f
'(#t #f #t #f #f)
))
; does not work
; error: Transformer may not be used as an expression: #[classifier-item 13]
(accumulate
and
#f
'(#t #f #t #f #f)
))
【问题讨论】:
-
作为一个疯狂的猜测,或者和和是不能像函数名一样传递的语法元素。
-
这些似乎是(未记录的?)麻省理工学院方案特有的术语。问题是
or和and是特殊形式,而不是过程。 -
感谢@molbdnilo,这很好。
-
分类器是句法分析的一部分,它决定表达式的类型(定义、lambda 主体、表达式等)。变压器是宏观系统的一部分,这很困难。