On Sunday, October 7, 2012 7:56:53 PM UTC-7, Ben wrote: > > On Sun, Oct 7, 2012 at 3:53 PM, Alan Malloy <al...@malloys.org<javascript:>> > wrote: > > This is nonsense. If s is fixed-size at compile-time, you would never > use > > apply to begin with. Why bother with (applyn 10 + [1 2 3 4 5 6 7 8 9 > 10]) > > when you could just write (+ 1 2 3 4 5 6 7 8 9 10)? > > Why bother to write (+ 1 2 3 4 5 6 7 8 9 10) when you could just write 55? > > In order to write (+ 1 2 3 4 5 6 7 ...) you need more than just the > length of the list, you need to know its contents as well. > > (let [s (take 10 (infinite-stream-of-random-integers))] (applyn 10 + s)) > > will work right---you know the length of s---but you're not going to > be able to just directly apply +. >
Of course apply will work fine. user> (apply + (take 10 (range))) 45 All applyn does is make the argument-unpacking code happen in your clojure source file instead of in RestFn.java, which is optimized for it, in exchange for the extremely small cost of dispatching on length. And since + only has different definitions for 0, 1, 2, or more arguments, that just means checking whether the argument sequence is 0, 1, 2, or more items long. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en