On Tue, Feb 22, 2011 at 1:35 AM, David Jagoe <[email protected]> wrote: > Hi Meikel, > > On 21 February 2011 15:18, Meikel Brandmeyer <[email protected]> wrote: >> Hi, >> >> Is there a reason, not to use the function object directly? > > Just that I wanted to prevent adding the same function multiple times.
You can compare functions for equality with = and the like. If you have two references to the exact same function object you'll get true, otherwise false. user=> (= + +) true user=> (= #(+ 3 %) #(+ 3 %)) false user=> (let [a #(+ 3 %)] (= a a)) true user=> (let [a +] (= + a)) true user=> The second test shows that functions that "are identical" mathematically or even code-wise may compare unequal, if the compiler has made separate function objects of them. The last shows that if a single function object is referenced in multiple places, this fact can be tested for with =. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
