我知道函数定义中的最小参数数量为零,但函数定义中的最大参数数量是多少?我只是为了知识和好奇而问这个问题,而不是我要写一个真正的功能.
可能重复:
在Lisp中,+函数实际上有多少输入?
以下代码给出了"太多参数"错误:
(setf u (loop for i upto 50000 collect 1))
(apply #'+ u)
Run Code Online (Sandbox Code Playgroud)
同样的
(apply #'= u)
Run Code Online (Sandbox Code Playgroud)
所以我想当用&rest写defun时,参数数量有一个上限.它是什么?我在这里搜索并尝试了该网站上的各种页面,但我无法弄清楚这一点.
我有以下 lisp 代码
(defun sum (vec)
"Summiert alle Elemente eines Vektors."
(apply '+ vec))
(defun square (item)
"Hilfsfunktion zum Quadrieren eines Elements."
(* item item))
(defun calcVarianz (vec)
"Berechnet die Varianz eines Vektors."
(loop with len = (length vec)
with mean = (/ (sum vec) len)
with some_func = (lambda (x) (* x x))
; causes the error
for item in vec
collecting (square (- item mean)) into squared
collecting (some_func item) into some_vector
; some_func cannot be found
finally …Run Code Online (Sandbox Code Playgroud)