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

后端 未结 5 1298
走了就别回头了
走了就别回头了 2020-12-18 04:02

I\'m relatively new to Lisp, and I was wondering if there really is an upper limit to the \"+\" function.

(I guess this applies to all the other arithmetic function

5条回答
  •  长情又很酷
    2020-12-18 04:30

    Simple answer, no, although a poor implementation using recursion and not tail recursion will have a stack limit.

    Depending upon your implementation + may be implemented using recursion or as a straight function call.

    I don't know Common Lisp well enough to know what requirements it specifies, but most implementations, if they use recursion, will use tail recursion and avoid any stack limits.

    A function call will be able to access the arguments as a list and so there is no limit to the number of arguments that can be processed.

    EDIT: Since someone has actually given a Common Lisp reference, it clearly should be a better answer, but I would have thought any good implementation would automatically apply the equivalent of (reduce #'+ arg-list) when enough arguments are supplied.

提交回复
热议问题