为什么lisp函数会评估错误的参数?

hig*_*dth -2 lisp common-lisp

我定义了一个函数来重复函数调用:

(defun repeat (n f x)
               (if (zerop n) x
                 (repeat ((- n 1) f (funcall f x)))))
Run Code Online (Sandbox Code Playgroud)

现在我想要申请cdr:

(repeat (1 (function cdr) '(1 2 4 5 6 7)))
Run Code Online (Sandbox Code Playgroud)

我清楚地提供n=1,f=cdrx='(1 2 3 4 5 6 7).它应该适用cdr一次.这是我收到的错误消息:

Error: Funcall of 1 which is a non-function. 
[condition type: TYPE-ERROR]
Run Code Online (Sandbox Code Playgroud)

但我有一个funcallcdr,不是1.

我正在使用Franz的Allegro Lisp的免费版本.

Gre*_*mer 6

Lisp中的函数调用语法是:

(<function> <arg1> <arg2> <arg3> ...)
Run Code Online (Sandbox Code Playgroud)

所以表达......

(1 (function cdr) '(1 2 4 5 6 7))
Run Code Online (Sandbox Code Playgroud)

......被评估为"调用该函数1的参数cdr'(1 2 4 5 6 7)".

换句话说,你有一组额外的括号.尝试:

(repeat 1 (function cdr) '(1 2 4 5 6 7))
Run Code Online (Sandbox Code Playgroud)

递归调用中存在同样的问题.