我需要将一些代码从 Scheme 翻译成 Common Lisp。现在,我有这样的东西:
(defun sum (term a next b)
(if (> a b)
0
(+ (term a) (sum term (next a) b))))
(defun sum-int (a b)
(defun (ident x) x)
(sum ident a 1+ b))
但它会产生错误。
*** - DEFUN: the name of a function must be a symbol, not (IDENT X)
请帮帮我。 谢谢
更新 原代码:
(define (sum term a next b)
(if (> a b)
0
(+ (term a) (sum term (next a) b))))
(define (sum-int a b)
(defun (identity x) x)
(define identity a 1+ b))
最佳答案
(defun sum (term a next b)
(if (> a b)
0
(+ (funcall term a) (sum term (funcall next a) next b))))
(defun sum-int (a b)
(flet ((ident (x) x))
(sum #'ident a #'1+ b)))
只是另一个 CL 使用 FLET(未经测试)。
关于function - scheme2lisp::define 函数并将其作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2932441/