Re: Please review macro

From: Kenny Tilton (ktilton_at_nyc.rr.com)
Date: 05/29/04


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


Relevant Pages

  • Re: modifying array access syntax
    ... I published recent speculation on the ARRAY ... > are in fact remnants of the property lists of these Lisp-N ... these that were meaningful at compile time (FEXPR, FSUBR, and MACRO ...
    (comp.lang.lisp)
  • Re: macro functionality in embedded languages.
    ... One advantage of the macro style is efficiency - the call expands at ... compile time and can be compiled with full optimization. ...
    (comp.lang.lisp)
  • Re: Question about compilation/evaluation environments
    ... compile time." ... "If a defmacro form appears as a top level form, ... store the macro definition at compile time, ... the macro later on in the file can be expanded correctly. ...
    (comp.lang.lisp)
  • Re: DISFAVORED Was: name for 3 PICK finally?
    ... complexity is reduced by reducing the phases of execution to keep ... outside happens when the word containing the macro executes. ... LITERAL COMPILE, .... ... ``GET LITERAL @ LITERAL `EXECUTE COMPILE,'' ...
    (comp.lang.forth)
  • Re: Open stack and colon definitions as a features (was: Of course it IS!!!)
    ... execute at compile time like immediate words did thirty years ... So now we also know what color a macro has: ... In Chuck's colorforth green is more like "]" and yellow is ... They do something more like change the system's STATE to execute ...
    (comp.lang.forth)