Hi, I'm (once again) despairing over some issues trying to integrate
one macro with another. Both are supposed to be used together to
generate a bunch of deftypes. Firstly, here's the one working
correctly (stripped out error checking for simplicity):

(defmacro swizzle*
  "Takes a class name, source instance, keyword and metadata map,
  returns new instance of type with fields populated based on
  decomposed single letter key lookups. E.g.

  (macroexpand-1 '(swizzle* Vec3 v :zyx))
  #_=> (new Vec3 (. v z) (. v y) (. v x) {})

  (macroexpand-1 '(swizzle* Vec3 v :xxz))
  #_=> (new Vec3 (. v x) (. v x) (. v z) {})
  "
  [clz src k meta]
  `(new ~clz
        ~@(->> k
               (name)
               (map (comp symbol str))
               (map (fn [f] `(. ~src ~f))))
        ~meta))

Now, where things go wrong is when I try to use this swizzle macro
from within the 2nd macro which generates the deftype skeleton (also
stripped down):

(defmacro defvec
  [n]
  (let [vname (symbol (str "Vec" n))
        syms (map (fn [s] (-> s str symbol)) (take n "xyzw"))]
    `(deftype ~vname [~@syms __meta#]

       clojure.lang.IObj
       (meta [this#] __meta#)
       (withMeta [this# mm#] (new ~vname ~@syms mm#))

       clojure.lang.ILookup
       (valAt [this# k#] (swizzle* ~vname this# k# __meta#))  ;; FIXME
       )))

(defvec 3)
CompilerException java.lang.IllegalArgumentException: No matching ctor
found for class compile__stub.user.Vec3,
compiling:(NO_SOURCE_PATH:1:1)

=:_(

I've been trying a lot of other versions (e.g. inline swizzle*,
defining it as local fn etc.), but honestly I don't understand why
this fails and would really appreciate some further insights into
these aspects of the dark art of macro voodoo.

Furthermore (for the future), in that second macro how can I add type
hints to the generated field names (they should all be doubles)...

Thanks a lot!

-- 
-- 
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
--- 
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to