Hi!

Am 03.02.2009 um 17:26 schrieb Mark Volkmann:

> On Tue, Feb 3, 2009 at 8:24 AM, Konrad Hinsen <konrad.hin...@laposte.net 
> > wrote:
>>
>> On Feb 3, 2009, at 14:49, Mark Volkmann wrote:
>>
>>> I see from the feedback so far that my statements are wrong.  
>>> However,
>>> I think it's true that there are *some* things you can do in a
>>> function that you cannot do in a macro, and perhaps vice-versa. Are
>>> those clearly documented anywhere? If not, what are some?
>>
>> I can't think of anything that would be "forbidden" in a macro but
>> "allowed" in a plain function. There are many things that don't make
>> sense in a macro, of course: launching agents, opening windows, ...
>
> Now I remember what I was thinking about. This isn't so much a
> difference between macros and functions as it is a rule about
> something you cannot do in a macro. Quoting from "Programming Clojure"
> ...
>
> "You cannot write a macro that expands to any of the syntactic sugar
> forms ... For example, you cannot write a macro that
> expands to (Math/PI)."
>
> "when you are writing macros, make sure they expand to ordinary forms,
> not any of the sugared short forms."

It's certainly ugly and inconvenient to do it this way, but it seems  
to work fine:

user=> (defmacro static-field [c f] (symbol (str (name c) \/ (name f))))
#'user/field
user=> (macroexpand-1 '(static-field Math PI))
Math/PI
user=> (static-field Math PI)
3.141592653589793

user=> (defmacro call-method [o m] `(~(symbol (str \. m)) ~o))
#'user/call
user=> (macroexpand-1 '(call-method "foo" toString))
(.toString "foo")
user=> (call-method "foo" toString)
"foo"

Kind regards,
achim


> -- 
> R. Mark Volkmann
> Object Computing, Inc.
>
> >


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