On Fri, Mar 6, 2009 at 7:55 AM, Mark Volkmann <[email protected]> wrote:
>
> When working on a list, both cons and conj add to the front. In my
> tests, cons is considerably faster than conj. I'm trying to figure out
> why.
In my testing they are the same speed.
> Here's the implementation of conj.
>
> (def
> #^{:arglists '([coll x] [coll x & xs])
> :doc "conj[oin]. Returns a new collection with the xs
> 'added'. (conj nil item) returns (item). The 'addition' may
> happen at different 'places' depending on the concrete type."}
> conj (fn conj
> ([coll x] (. clojure.lang.RT (conj coll x)))
> ([coll x & xs]
> (if xs
> (recur (conj coll x) (first xs) (next xs))
> (conj coll x)))))
>
> The line for the parameter list [coll x] seems to call itself
> recursively with the exact same arguments. How does that ever
> terminate?
You're probably getting confused by the old-style Java interop syntax.
(. clojure.lang.RT (conj coll x))
is the same as:
(clojure.lang.RT/conj coll x)
--Chouser
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---