[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Using a macro definition within a explicit renaming
From: |
Peter Bex |
Subject: |
Re: [Chicken-users] Using a macro definition within a explicit renaming macro. |
Date: |
Fri, 11 Feb 2011 21:20:03 +0100 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Feb 11, 2011 at 03:13:36PM -0500, Patrick Li wrote:
> Hello,
> 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:
> say-hi
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)
(define-syntax say-hi
(syntax-rules ()
((say-hi) (display "Hello!")))))
(import-for-syntax foo)
(define-syntax my-renaming-macro
(lambda (expression rename comparison)
(say-hi)
'(quote output-expression)))
(my-renaming-macro whatever)
There may be a shorter way involving begin-for-syntax or something.
Cheers,
Peter
--
http://sjamaan.ath.cx
--
"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