Karsten Schmidt writes:
> 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):
...
> (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.
Recursive macro expansion is an important debugging aid for macro writers:
(use 'clojure.tools.macro)
(mexpand-all '(defvec 3))
returns
(let* []
(deftype* Vec3 user.Vec3 [x y z __meta__1154__auto__]
:implements [clojure.lang.IObj clojure.lang.ILookup clojure.lang.IType]
(user/valAt [this__1155__auto__ k__1157__auto__]
(new Vec3
(. this__1155__auto__ k)
(. this__1155__auto__ _)
(. this__1155__auto__ _)
(. this__1155__auto__ 1)
(. this__1155__auto__ 1)
(. this__1155__auto__ 5)
(. this__1155__auto__ 7)
(. this__1155__auto__ _)
(. this__1155__auto__ _)
(. this__1155__auto__ a)
(. this__1155__auto__ u)
(. this__1155__auto__ t)
(. this__1155__auto__ o)
(. this__1155__auto__ _)
(. this__1155__auto__ _)
__meta__1154__auto__))
(clojure.core/meta [this__1155__auto__] __meta__1154__auto__)
(user/withMeta [this__1155__auto__ mm__1156__auto__] (new Vec3 x y z mm__1156__auto__)))
(do (clojure.core/import* "user.Vec3"))
(def ->Vec3 (fn* ([x y z __meta__1154__auto__] (new user.Vec3 x y z __meta__1154__auto__))))
user.Vec3)
So the problem is that your swizzle* macro takes apart the symbol
generated from k#.
I suspect you want to pass a keyword such as :x to valAt at
runtime. In that case, you can't decompose it using a macro at compile
time.
Konrad.