Hi,
maybe this gives you a hint, one why it happens:
user=> (let [k :xyz] (macroexpand-1 '(swizzle* Vec3 v k {})))
(new Vec3 (. v k) {})
The problem is that swizzle* is a macro. It has no access to runtime
information! It sees only the symbol not its value. Calling it with a
literal keyword works, thusly. You could hardwire some functions in case
the number of coordinates is always three:
(defmacro defswizzlers
[]
(let [v (gensym "v")]
`(do ~@(for [x "xyz"
y "xyz"
z "xyz"]
`(defn ~(symbol (str x y z))
[~(with-meta v {:tag `Vec3})]
(Vec3. ~@(map (fn [s] `(. ~v ~(symbol (str s)))) [x y z])
(meta ~v)))))))
(defswizzlers)
Then you can simply call like (zyx v) instead of (:zyx v).
But all that is very, very static.
Kind regards
Meikel
--
--
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
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.