On Sat, Jul 13, 2019 at 08:26:56AM +0200, Marco Maggi wrote:
> I would like to write such macro as:
> (import (scheme)
> (chicken fixnum))
> (import-for-syntax (scheme)
> (only (chicken syntax)
> (only (my-lib)
> (define-syntax spiffy
> (lambda (input-form.stx rename compare)
> (define %fx+ (doit rename))
> and in the library "(my-lib)" I have:
> (define (doit rename)
> (rename 'fx+))
> but for this to work cleanly: in "(my-lib)" I should import "fx+" at
> level -1? Is it right?
This won't work. "rename" is operating in the syntactic environment
of the transformer. You can pass it as a procedure to some other module,
but that won't change its internal state.
> This is possible with R6RS implementations. How about CHICKEN?
That is very surprising to me. It should not be possible. You're
probably comparing apples and oranges (syntax-case works differently
from ER macros).
On Sat, Jul 13, 2019 at 02:12:48PM +0200, Marco Maggi wrote:
> Peter Bex wrote:
> > This won't work. "rename" is operating in the syntactic environment
> > of the transformer. You can pass it as a procedure to some other module,
> > but that won't change its internal state.
> So, is RENAME closed upon the environment in which ER-MACRO-TRANSFORMER
> is called? So I can do something like:
Yes, that's how it should work.
> I'm not trying to inject syntactic bindings in the original
> environment, I just want to put as much as possible of a macro body into
> a separate library to be imported "for syntax".
Personally, I find that confusing, because the module containing the
macro definition determines the available identifiers. If you then move
the actual expansion code to another module, that doesn't give a clue as
to which identifiers are available in the expansion.
So for stylistic reasons I'd avoid that. You can still move processing
code to another module, but I would pass the renamed identifiers to the
helper procedure, instead of the "rename" procedure itself.