我正在使用Little Schemer,我试图将所有答案转换为Common Lisp。 在第8章中,讨论了匿名函数,并返回了匿名函数。 例如:通过匿名函数循环常见Lisp vs. Scheme
(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中是不可能的吗?