我正在使用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中是不可能的嗎?