On Sat, Mar 13, 2010 at 9:32 AM, Jonathan Shore <jonathan.sh...@gmail.com> wrote: > Hi, > > I've been evaluating clojure with a bias around performance (I do a lot of > numerical work). I don't need to the metal, but want to see that > fundamental operations are comparable to java in performance and that > performance can be had not at the expense of conciseness. In particular, > I've noted that arithmetic such as: > > (+ a b c d) > > is not equivalent to: > > (+ (+ (+ a b) c) d) > > in performance, because the former form applies + on a list or array form (I > forget which). This is regardless of whether all of the above values have > primitive type hints. At least this is what I observe in debugging (correct > me if I am wrong). > > Could + and other operators be changed to a macro mapping rather than the > current defn, mapping the argument list to a binary expression tree (+ (+ (+ > ... instead of the list style application (I'm guessing yes, not being > familiar with CL-style macros).
Yes. It's a simple matter of changing the current run-time reduce in (defn + ...) to a compile-time reduce: ([x y & more] (reduce (fn [a b] `(+ ~a ~b)) (cons x (cons y more)))) -Per -- 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