I'm trying out various examples in The Joy Of Clojure and I'm in
Chapter 12 Performance looking at type hinting.
The authors give this example:
(set! *warn-on-reflection* true)
; true
(defn asum-sq [xs]
(let [dbl (amap xs i ret
(* (aget xs i)
(aget xs i)))]
(areduce dbl i ret 0
(+ ret (aget dbl i)))))
; Reflection warning, NO_SOURCE_PATH:2 - call to aclone can't be resolved.
Plus lots of others:
Reflection warning, NO_SOURCE_PATH:2 - call to alength can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to aset can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to alength can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved.
NO_SOURCE_FILE:2 recur arg for primitive local: ret is not matching
primitive, had: Object, needed: long
Auto-boxing loop arg: ret
Reflection warning, NO_SOURCE_PATH:2 - call to alength can't be resolved.
Reflection warning, NO_SOURCE_PATH:2 - call to aget can't be resolved.
#'user/asum-sq
They claim if you use ^floats as a type hint, this will solve the
problem, but here's what I get (on Clojure 1.3):
(defn asum-sq [ ^floats xs ]
(let [ ^floats dbl (amap xs i ret
(* (aget xs i)
(aget xs i)))]
(areduce dbl i ret 0
(+ ret (aget dbl i)))))
Reflection warning, NO_SOURCE_PATH:3 - call to aclone can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to alength can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to aset can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to alength can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved.
NO_SOURCE_FILE:3 recur arg for primitive local: ret is not matching
primitive, had: Object, needed: long
Auto-boxing loop arg: ret
Reflection warning, NO_SOURCE_PATH:3 - call to alength can't be resolved.
Reflection warning, NO_SOURCE_PATH:3 - call to aget can't be resolved.
#'user/asum-sq
In other words, the same set of reflection warnings.
Trying either version of asum-sq blows up tho'...
(time (dotimes [_ 10000] (asum-sq (float-array [1 2 3 4 5]))))
; IllegalArgumentException No matching method found: aset
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:77)
Shouldn't it at least run, albeit slowly?
Simplifying the example somewhat:
(def xs (float-array [1 2 3 4 5]))
; #'user/xs
(amap xs i ret (* (aget xs i) (aget xs i)))
; Reflection warning, NO_SOURCE_PATH:12 - call to aclone can't be resolved.
; Reflection warning, NO_SOURCE_PATH:12 - call to alength can't be resolved.
; Reflection warning, NO_SOURCE_PATH:12 - call to aget can't be resolved.
; Reflection warning, NO_SOURCE_PATH:12 - call to aget can't be resolved.
; Reflection warning, NO_SOURCE_PATH:12 - call to aset can't be resolved.
; IllegalArgumentException No matching method found: aset
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:77)
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
--
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