Thanks Rich,

Expanding into the symbol is clever, but less readable (IMO) than just  
expanding into the . form. Anyway, I get it now.

Stuart

> On Feb 15, 2009, at 9:06 AM, Stuart Halloway 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
>
>
> First off, 'sugared forms' is too imprecise to talk about. More
> precise is, you can't write a macro that expands into a reader  macro,
> because reading is finished. But that is not the case here. Again,
> start with, what do I want to write, and what expansion do I want?
>
> I want to write:
>
> (call-static foo bar)
>
> I want it to expand into:
>
> (foo/bar)
>
> Note the expansion does not contain any reader macros, so you can do
> it. It is also important not to lose track of the data structures (not
> strings!) you are manipulating. The expansion above is a list with one
> (namespace-qualified) symbol in it. You can't get a namespace-
> qualified symbol by putting two symbols on either side of a /  ,
> instead:
>
> (defmacro call-static [cls member]
>   `(~(symbol (str cls) (str member))))
>
> (macroexpand '(call-static foo bar))
> (foo/bar)
>
> (call-static System nanoTime)
> -> 1234708658498938000
>
> Rich
>
>
>
> >


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

Reply via email to