guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: procedure->macro vs procedure->memoizing-macro again


From: Marius Vollmer
Subject: Re: procedure->macro vs procedure->memoizing-macro again
Date: 24 May 2001 04:30:20 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102

Sergey Dolin <address@hidden> writes:

> Some time ago I described the problem. And had got the solution.
> But it does not works for all cases.
> 
> I want to have (http:let ...) macros:
> 
> (define-macro (http:let bindings . body)
>       `(let (,@bindings
>                  ,@(some-bindings-generator))
>                  ,@body))
> 
> Looks nice. But (some-bindings-generator) is called only once because
> of implementstion define-macro with procedure->memoizing-macro.

Yes, that's a correct behaviour of define-macro.  You can not rely on
macros being expanded more than once, or even in the same environment
that the expanded code is run in.  For example, imagine a compiler.
It will expand your macros once when compiling.  When the compiled
code is finally executed, the macro is not expanded again.  The
compiled code might execute on a different machine on a different
continent, so you should not make any assumptions in your macro
expander about the environment that the final code is executing in.

You should also forget about the differences between procedure->macro
and procedure->memoizing-macro.  You should never use any of these.

What you can do is make `some-bindings-generator' return not something like

    (foo 14)

where `foo' is bound to a constant.  Rather, make it return something
like this:

    (foo (compute-foo-value))

where `compute-foo-value' is a function that will return the value
that is currently the right one for `foo'.


That is, instead of

    (define (some-bindings-generator)
      `(foo ,(compute-foo-value)))

use this

    (define (some-bindings-generator)
      `(foo (compute-foo-value)))

Does this help?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]