Re: rules for writing macros

2009-02-15 Thread Stuart Halloway
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

Re: rules for writing macros

2009-02-15 Thread Chouser
On Sun, 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): > > (defmacr

Re: rules for writing macros

2009-02-15 Thread Rich Hickey
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 c

Re: rules for writing macros

2009-02-15 Thread Stuart Halloway
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.Ex

Re: rules for writing macros

2009-02-04 Thread Nathanael Cunningham
I just wanted to point out that ' is syntactic sugar for (quote) not (list). (list) will evaluate your arguments, where as '() will not. So if you try to use them interchangeable you'll run into trouble. user> (list 1 2 (+ 1 2)) (1 2 3) user> '(1 2 (+ 1 2)) (1 2 (+ 1 2)) Its a pretty common lisp

Re: rules for writing macros

2009-02-04 Thread CuppoJava
Personally I find that the clearest way to think about macros, is to treat them like a *very* advanced search-and-replace feature. Just keep in mind that macros expand into code, and check to make sure that your generated code is indeed valid code. --~--~-~--~~~---~--~-

Re: rules for writing macros

2009-02-04 Thread H Durer
Marde, Feb 3, 2009 at 14:24, Konrad Hinsen skribis: [...] > 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, ... Well, for normal functions y

Re: rules for writing macros

2009-02-04 Thread Stuart Halloway
Thanks Mark, Chouser, I will update that section of the book with a corrected example in Beta 7. Cheers, Stuart > > On Tue, Feb 3, 2009 at 11:26 AM, Mark Volkmann > wrote: >> >> Now I remember what I was thinking about. This isn't so much a >> difference between macros and functions as it is

Re: rules for writing macros

2009-02-03 Thread Daniel Jomphe
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? You migh

Re: rules for writing macros

2009-02-03 Thread Achim Passen
Hi! Am 03.02.2009 um 17:26 schrieb Mark Volkmann: > On Tue, Feb 3, 2009 at 8:24 AM, Konrad Hinsen > 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 y

Re: rules for writing macros

2009-02-03 Thread Chouser
On Tue, Feb 3, 2009 at 11:26 AM, Mark Volkmann wrote: > > 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 tha

Re: rules for writing macros

2009-02-03 Thread Mark Volkmann
On Tue, Feb 3, 2009 at 8:24 AM, Konrad Hinsen 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 perha

Re: rules for writing macros

2009-02-03 Thread Konrad Hinsen
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

Re: rules for writing macros

2009-02-03 Thread Mark Volkmann
On Tue, Feb 3, 2009 at 7:32 AM, Konrad Hinsen wrote: > > On Feb 3, 2009, at 14:01, Mark Volkmann wrote: > >> Are the following statements true? They aren't discussed at >> http://clojure.org/macros, but I think they are true. >> >> Macros cannot call other macros during their evaluation, but they

Re: rules for writing macros

2009-02-03 Thread Konrad Hinsen
On Feb 3, 2009, at 14:01, Mark Volkmann wrote: > Are the following statements true? They aren't discussed at > http://clojure.org/macros, but I think they are true. > > Macros cannot call other macros during their evaluation, but they can > expand to code that calls macros. Macros can certainly

Re: rules for writing macros

2009-02-03 Thread GS
On Feb 4, 12:01 am, Mark Volkmann wrote: > Are the following statements true? They aren't discussed > athttp://clojure.org/macros, but I think they are true. > > Macros cannot call other macros during their evaluation, but they can > expand to code that calls macros. I don't know, but I'll br

rules for writing macros

2009-02-03 Thread Mark Volkmann
Are the following statements true? They aren't discussed at http://clojure.org/macros, but I think they are true. Macros cannot call other macros during their evaluation, but they can expand to code that calls macros. Macros cannot use syntactic sugar such as '(items) to create a list and instea