Re: Please review macro
From: Kenny Tilton (ktilton_at_nyc.rr.com)
Date: 05/29/04
- Next message: Chris Capel: "Re: Please review macro"
- Previous message: Kalle Olavi Niemitalo: "Re: Please review macro"
- In reply to: Svein Ove Aas: "Re: Please review macro"
- Next in thread: Kalle Olavi Niemitalo: "Re: Please review macro"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 May 2004 20:12:19 GMT
Svein Ove Aas wrote:
> Kenny Tilton wrote:
>
>
>>>I'm not entirely sure what's up with append-elements in the if.
>>>Shouldn't you have a , before it?
>>
>>Not the way he is using it, which is to make interesting decisions at
>>compile time about into what code the particular macro invocation should
>>expand. More concretely, the comma at the start of ,(if
>>append-elements... ) holds for the whole form following it, so things in
>>there are compile-time code with direct access to the macro args.
>>
>
> No, you're quite right. I didn't notice the , before (if, and that does
> make a lot more sense.
>
>
>>But you might have meant that the macro would be more useful if
>>append-elements were evaluated at run time. If so, I agree. Otherwise we
>>get this:
>>
>>CELLS(7): (defmacro t-f (t-or-f) (if t-or-f `'true `'false))
>>T-F
>>CELLS(8): (t-f t)
>>TRUE
>>CELLS(9): (t-f nil)
>>FALSE
>>CELLS(10): (t-f (not t))
>>TRUE <uh-oh>
>>
> Eh.
> I'll go read On Lisp again.
:) Better yet, add (print t-or-f) to the above macro and (when (listp
t-or-f) (print (car t-or-f))), and try different calls such as:
(t-f 'hi-mom)
Also, macroexpand a form and see your print statements run, evaluate
them and see them not run. Mind you, at the repl I guess you get both
compile-time and then right away run-time, so it may not produce such
dramatic results unless you compile the macro first.
This is also how one debugs macros, and soon enough one internalizes
compile vs run time and can toss off macros without much thought,
switching back and forth between the compiletime code being written and
runtime code one has in mind.
kenny
-- Home? http://tilton-technology.com Cells? http://www.common-lisp.net/project/cells/ Cello? http://www.common-lisp.net/project/cello/ Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film Your Project Here! http://alu.cliki.net/Industry%20Application
- Next message: Chris Capel: "Re: Please review macro"
- Previous message: Kalle Olavi Niemitalo: "Re: Please review macro"
- In reply to: Svein Ove Aas: "Re: Please review macro"
- Next in thread: Kalle Olavi Niemitalo: "Re: Please review macro"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|