Cedric Greevey <cgree...@gmail.com> writes: Hi Cedric,
> Actually, on further testing, I'm not sure that (def ^{Double/TYPE} > ...) is really working either, rather than boxing and then unboxing on > each call: > > user=> (def ^{:tag Double/TYPE} b (fn [^double x] (+ x 0.5))) > #'user/b > user=> (defn c ^double [^double x] (+ x 0.5)) > #'user/c > user=> (pt (b 0.1)) > :double > user=> (pt (c 0.1)) > :double > > So far, so good? But: > > user=> (ancestors (.getClass b)) > #{java.util.concurrent.Callable clojure.lang.AFn clojure.lang.IObj > clojure.lang.IFn clojure.lang.IFn$DO clojure.lang.IMeta > java.lang.Object java.io.Serializable java.lang.Runnable > java.util.Comparator clojure.lang.AFunction clojure.lang.Fn} > > IFn$DO? A Function that gets a double and returns an object, I think. That would support your claim that b doesn't return a primitive double, although the Var is tagged. > user=> (ancestors (.getClass c)) > #{java.util.concurrent.Callable clojure.lang.AFn clojure.lang.IObj > clojure.lang.IFn$DD clojure.lang.IFn clojure.lang.IMeta > java.lang.Object java.io.Serializable java.lang.Runnable > java.util.Comparator clojure.lang.AFunction clojure.lang.Fn} > > IFn$DD? Gets and returns a primitive double. > user=> (def d (fn ^double [^double x] (+ x 0.5))) > #'user/d > user=> (ancestors (.getClass d)) > #{java.util.concurrent.Callable clojure.lang.AFn clojure.lang.IObj > clojure.lang.IFn$DD clojure.lang.IFn clojure.lang.IMeta > java.lang.Object java.io.Serializable java.lang.Runnable > java.util.Comparator clojure.lang.AFunction clojure.lang.Fn} > > IFn$DD again here. Hm, strange. That means (to my best understanding), that the function is correctly compiled to have a primitive version. So maybe it's just the call to anonymous functions that requires :arglists metadata to correctly resolve the primitive version... > This really *should* be simple. Therefore, there's a bug somewhere. > But I'm not sure where. Compiler.java, most likely. At least, it seems that (fn ^double [^double x] (+ x 0.5)) compiles to a class supporting primitive, unboxed calls. Bye, Tassilo -- 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