Part of the problem is that you confuse compile time and runtime.

Macro are evaluated at compile-time.

So when you write:

(my-macro SomeClass. a b) , my-macro can't access the runtime value of a and b.

So if you want your second example to work, you need flatten to be
called at runtime and not macro-expansion time.

So, if you wanted to apply my-macro to a function, and not a
constructor, something like:

(defn my-macro [fun & args]
  (apply fun (flatten args)))

should work.

However, it probably don't work for SomeClass., which is not a function.

 One way to solve that is to define a function wrapping around
SomeClass. with the  right number of arguments.

Another way is to do a macro which use reflection to look at the
number of arguments of SomeClass. at compile time
and eta-expand it. (ie change (my-macro SomeClass. & args) into (apply
  (fn [ x1 .... xn ]  (SomeClass. x1 ... xn)) (flatten args)), where
n is computed using reflection).

If SomeClass. takes different possible number of arguments, then the
expansion is a bit more complex because you need to check the number
of arguments at runtime
and call the right constructor.

Best,

Nicolas.

-- 
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

Reply via email to