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

后端 未结 5 1296
走了就别回头了
走了就别回头了 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:43

    Clojure provides an example of a Lisp where you can actually have an infinite number of arguments to a function, via the use of lazy sequences:

    ; infinite lazy sequence of natural numbers
    (def naturals (iterate inc 1))
    
    (take 10 naturals)
    => (1 2 3 4 5 6 7 8 9 10)
    
    ; add up all the natural numbers 
    (apply + naturals)
    => ...... [doesn't terminate]
    

    Not particularly useful, of course.....

提交回复
热议问题