Hello,

stuhood a écrit :
> Functions like (+), (*), (-), (and probably more) should support
> sequences as parameters.
>
> The current way to accomplish this (without implementing your own sum
> using reduce) seems to be:
>   
>> (apply + (map #(. Math pow 2 %) (range 10)))
>>     
> ... which has to generate the sequence first.
>   
This is a common misconception: passing a seq to apply doesn't force its 
evaluation.
You can test this fact by passing an infinite seq to a function:
(defn second-arg [& args]
  (second args))
user=> (apply second-arg (iterate inc 0))
1


and (apply + some-seq) is really equivalent to (reduce + some-seq), see 
the def of + in core.clj:
(defn +
...
  ([x y & more]
   (reduce + (+ x y) more)))

Christophe

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)



--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to