Howard Lewis Ship a écrit :
> I have to wonder a bit about the ability to optimize.  Everything
> boils down to one of the seven or so basic forms.  That's a lot of
> function calls to do even small things, like adding numbers. You might
> think that simple math would be optimized and inlined, but it isn't:
>
> Clojure
> user=> (doc +)
> -------------------------
> clojure.core/+
> ([] [x] [x y] [x y & more])
>   Returns the sum of nums. (+) returns 0.
> nil
> user=> (ns clojure.core)
> #<Namespace clojure.core>
> clojure.core=> (defn + [x y] (* x y))
> #'clojure.core/+
> clojure.core=> (+ 3 5)
> 15
> clojure.core=>
>
> This implies, to me, that Clojure is doing a full functional call,
> with dynamic lookup via the namespace, even for +.  To me, this means
> that Clojure will never be as fast as Java code *when implementing the
> same algorithm*.  Clojure will be faster when taking advantage of
> laziness and concurrency and that's fine by me.
>   

Not quite. + (and al.) gets special treatment, it is inlined:
clojure.core=> (defn add [x y] (+ x y))
#'clojure.core/add
clojure.core=> (defn + [x y] (* x y))
#'clojure.core/+
clojure.core=> (+ 3 5)
15
clojure.core=> (add 3 5)
8

This allows, in a tight loop, the jit to emit code as fast as equivalent 
java code.

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