3

Possible Duplicate:
In Lisp, how many inputs can the + function actually have?

The following code gives a "too many argument" error:

(setf u (loop for i upto 50000 collect 1))
(apply #'+ u)

similarly for

(apply #'= u)

So I guess when writing defun with &rest there is an upper bound for the number of arguments. What is it? I searched and tried here and various pages on that site but I couldn't figure this out.

Community
  • 1
  • 1
h__
  • 865
  • 1
  • 11
  • 19
  • 1
    A language specification is not an implementation. Ideally there would be "no limit", but implementations (and hardware limits) .. –  Aug 01 '12 at 06:55
  • I see. So it depends on implementation. I just wanted to know whether the language set an lower bound on this. I tried out `(defun crazy(n) (apply #'+ (loop for i upto n collect 1)))` in CLisp and Clozure CL, it is 4095 and 65535 respectively. – h__ Aug 01 '12 at 06:57
  • well you can expect any implementation to take at least 3 arguments, you probably want an upper bound for that lower bound now, don't you? :-) – hroptatyr Aug 01 '12 at 06:58
  • Yeah, i wanted a lower bound of max. And now I found the answer is given by CALL-ARGUMENTS-LIMIT – h__ Aug 01 '12 at 06:59

1 Answers1

5

There is a constant called CALL-ARGUMENTS-LIMIT that gives you the upper bound of how many arguments you can pass to a function.

However, in your initial example, you can definitely use REDUCE:

(reduce #'+ u)
Vatine
  • 20,782
  • 4
  • 54
  • 70