Or perhaps code like this ought to be structured completely
differently in order to avoid reflection, and it was just a fluke that
it worked in 1.2?
Thanks,
Andy
(ns nbody
(:gen-class))
(set! *warn-on-reflection* true)
(definterface IBody
(^double x [])
(^double y [])
(^double z [])
(^double dist [other]))
(deftype Body [^{:unsynchronized-mutable true :tag double} x
^{:unsynchronized-mutable true :tag double} y
^{:unsynchronized-mutable true :tag double} z ]
IBody
(x [this] x)
(y [this] y)
(z [this] z)
(dist [this other]
(let [^Body nbody other
dx (- x (.x nbody)) ; first reflection warning here
dy (- y (.y nbody)) ; second here
dz (- z (.z nbody)) ; third here
dsq (+ (* dx dx)
(+ (* dy dy)
(* dz dz)))]
(Math/sqrt dsq))))
(defn -main [& args]
(let [b (Body. 0 0 0)]
(println "pos:" (.x b) (.y b) (.z b))))
Stu
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
If I change the name 'nbody' in these lines:
> (let [^Body nbody other
> dx (- x (.x nbody)) ; first reflection warning here
> dy (- y (.y nbody)) ; second here
> dz (- z (.z nbody)) ; third here
to some name that is not the name of the namespace, like 'nbo', then
the reflection warnings go away:
> (let [^Body nbo other
> dx (- x (.x nbo)) ; first reflection warning here
> dy (- y (.y nbo)) ; second here
> dz (- z (.z nbo)) ; third here
If I then change the ns declaration at the top to "ns nbo", the
reflection warnings come back again.
Easy to avoid the problem, once you know.
Andy
I replied to my own message with a workaround that it seems to be
related to the variable 'nbody' having the same name as the one in the
'ns' declaration.
Thanks,
Andy