Re: Lisp2Perl - Lisp to perl compiler

From: Pascal Costanza (costanza_at_web.de)
Date: 01/28/04


Date: Wed, 28 Jan 2004 01:44:13 +0100


Joe Marshall wrote:

> At runtime, though, you want to be able to change a regular function
> into a dynamic one should you so desire.
>
> There's no problem with doing this with Matthew's module system.

OK.

> As should be obvious, utility functions such as `EMBEDDED-DOT-P' and
> `SPLIT-ON-DOTS' *must* be present before we can expand the macros.
> There is simply no way to get around that! When compiling a
> *different* file that uses this macro, you *must* ensure that the file
> that defines EMBEDDED-DOT-P is loaded first. This is a compile-time
> dependency, but this dependency must be maintained.

OK.

> It often happens that you accidentally introduce these dependencies
> through incremental editing of files: you load up the compiled files,
> edit some code, recompile that file, edit some more, do more
> recompiles etc. At some point, you decide to recompile from scratch,
> but all hell breaks loose because you added a macro whose expansion
> depends on code that is compiled *after* the macro is used. It only
> accidentally worked during development because you never attempted to
> recompile the utility file that expanded the macro, only those files
> that used it.

OK, I understand the problem better by now. I actually recall having it.

> What Matthew's module system does is ensure that code that the macro
> *uses* at compile time is in scope at compile time and not
> accidentally obtained from the runtime environment. Errors such as
> the above are caught sooner because incremental compilation and whole
> world compilation are treated more uniformly.

OK, thanks for clarifying my misunderstanding of that paper.

But I still wonder what's the reason why this works:

> (define a 1)
>
> (define-syntax foo
> (syntax-rules ()
> ((foo x) (+ a x))))
>
> (foo 2) => 3

...while that doesn't:

>>(define a 1)
>>(define-macro (foo x) `(+ ,a ,x))
>>(foo 2)
>>
>>This will result in a "reference to undefined identifier" error,
>>because the foo macro doesn't see the a reference.

What's the difference here?

Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."


Relevant Pages

  • Re: Separating evaluation and compilation environments.
    ... compilation and evaluation environments long before that. ... a baz definition and expanding out the foo macro forces you to recompile ... that definition if you redefine foo but intend to use baz again. ...
    (comp.lang.lisp)
  • Re: Question about compilation/evaluation environments
    ... I guess it depends on what you mean by evaluating some code. ... In this case, the form is the macro function, aka macro ... >> expander, aka expansion function... ... compilation of function and macro definitions. ...
    (comp.lang.lisp)
  • Re: Why doesnt Lisp automatically differentiate functions and macros?
    ... evaluation, compilation, and run-time environments. ... Note that because the CLHS forbids macro functions from ... Common Lisp macro functions *can* do system calls at macro ... create/modify global data at compile time. ...
    (comp.lang.lisp)
  • CMUCL optimizer [was Re: Sacla loop: a new loop implementation]
    ... explore type information at macroexpansion time to decide the macro ... (defmethod generic-iter ((obj symbol) ... In order to measure the compilation and load time I decided to create ...
    (comp.lang.lisp)
  • Re: Difference between Macro and Function...
    ... |>between a freemacro and a freefunction ??.... ... | throughout the whole process of compilation, ... to exist through the linking or execution phases. ... Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org ...
    (comp.lang.c)