【发布时间】:2017-04-11 23:30:57
【问题描述】:
我正在研究 Little Schemer,我正在尝试将所有答案转换为 Common Lisp。 第 8 章讨论了匿名函数以及返回匿名函数。 例如:
(define insertL-f
(lambda (test?)
(lambda (new old l)
(cond
((null? l) (quote ()))
((test? (car l) old) (cons new l)))
(else (cons (car l) ((insertL-f test?) new old (cdr l))))))))
我的代码:
(defun insertL-f (test)
(lambda (new old l)
(cond
((null l) '())
((funcall test (car l) old) (cons new l))
(t (cons (car l) (insertL-f test) new old (cdr l))))))
问题出在第二个代码块的最后一行。我收到错误“cons 的参数太多”,但我不能像 Scheme 代码那样添加一对额外的括号。这种递归风格在 Common Lisp 中是不可能的吗?
【问题讨论】:
标签: scheme common-lisp