[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Using a macro definition within a explicit renaming
Re: [Chicken-users] Using a macro definition within a explicit renaming macro.
Fri, 11 Feb 2011 21:20:03 +0100
On Fri, Feb 11, 2011 at 03:13:36PM -0500, Patrick Li wrote:
> I'm working with explicit renaming macros, and I'm having a lot of trouble
> using macros within them.
> (define-syntax say-hi
> (syntax-rules ()
> ((say-hi) (display "Hello!"))))
> (define-syntax my-renaming-macro
> (lambda (expression rename comparison)
> (say-hi) <-- Attempt to call predefined macro
> '(quote output-expression)))
> When I run (my-renaming-macro) I get :
> Error: during expansion of (my-renaming-macro ...) - unbound variable:
That's a phasing problem. Macros can use only macros that are
imported for the macro expansion process using import-for-syntax
because all macros are defined in the macro environment, which
differs from the macro *expansion* environment.
This works though:
(module foo (say-hi)
(import chicken scheme)
((say-hi) (display "Hello!")))))
(lambda (expression rename comparison)
There may be a shorter way involving begin-for-syntax or something.
"The process of preparing programs for a digital computer
is especially attractive, not only because it can be economically
and scientifically rewarding, but also because it can be an aesthetic
experience much like composing poetry or music."
-- Donald Knuth