On Sun, Feb 15, 2009 at 9:06 AM, Stuart Halloway <stuart.hallo...@gmail.com> wrote: > > Does this clarify the point I was making? > > When writing macros, you cannot dynamically build one of the syntactic > sugar forms. For example, you cannot write a macro that expands cls > and member into (cls/member): > > (defmacro call-static [cls member] `(~cls/~member)) > -> java.lang.Exception: Invalid token: cls > > Instead, you should build normal, unsugared forms: > > (defmacro call-static [cls member] `(. ~cls ~member)) > -> nil
I think you actually can have a macro that *expands* into the sugar forms, though the ~ unquote symbol indeed won't work within a single symbol as in your first example. On the other hand, your second example is definitely better than this: (defmacro call-static [cls member & args] (cons (apply symbol (map str [cls member])) args)) (macroexpand-1 '(call-static Integer parseInt "25")) -> (Integer/parseInt "25") (call-static Integer parseInt "25") -> 25 --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---