The expression is expanded in the syntactic environment of the
er-macro-transformerexpression, and the expanded expression is evaluated in the transformer environment to yield a macro transformer as described below. This macro transformer is bound to a macro keyword by the special form in which thetransformerexpression appears (for example,let-syntax).
Chicken has a separate environment for macro expansion,
and modules are loaded into this with `import-for-syntax'.
In the r7rs egg, I believe everything imported for the runtime
also gets imported into the compilation environment so things
just work.
(define (kadr expression)(cadr expression))(define-syntax foo(er-macro-transformer(lambda (expression rename compare)(kadr expression))))(foo (display "Hello, World!"))(newline)
(define-syntax bar(syntax-rules ()((bar . args)(lambda . args))))(define-syntax foo(er-macro-transformer(bar (expression rename compare)(cadr expression))))(foo (display "Hello, World!"))(newline)
The trick to specifying an ER SRFI would not so much be in
specifying ER itself, but in specifying the semantics of different
phases in a way to make all implementations happy.
Are you interested? :)
(import eval)...(er-macro-transformer(eval '(lambda (expr rename compare) ...) (environment '(scheme base) ...)))
(er-transformer ((scheme base) ...) (lambda (expr rename compare) ...))
Chicken core is not R7RS, you need to (use r7rs).
Even then, I don't think this will work. Chicken only aims
for r7rs-small compatibility, so only needs to support
syntax-rules. You can maybe hack around this with
(eval-when (compile runtime)
(define (kadr expression) ...))
(let loop ((x 0))(when (< x 10)(let ()
(define-syntax foo(er-macro-transformer(lambda (expression rename compare)
`(,(rename 'begin)(,(rename 'display) ,x)(,(rename 'newline))))))(foo)(loop (+ x 1)))))
Yep, this is a known limitation
(https://github.com/ashinn/chibi-scheme/issues/259).
Contrary to what you've been suggesting, chibi doesn't mix runtime and
compile time bindings well :)
(define x (read-line))(define-syntax foo(er-macro-transformer(lambda (expr rename compare)x)))(display (foo))(newline)
Either way, this hardly makes ER macros more nor less portable.
Every macro system has its own extensions, and basically no two
implementations have identical macro systems. All of R7RS-small
is built around "is an error" semantics, to explicitly allow extensions.
This is one of the beauties of Scheme, that it allows agreement on
a minimal core while encouraging experimentation.
Let's agree on that core before even discussing forbidding variety.
--
Alex
So could a common core be based on the following?"The argument to er-macro-transformer is expanded and evaluated in the environment defined by the import sets of the import declarations of the current module. It is an error if any of the identifiers referenced while expanding and evaluating the transformer is shadowed by local bindings in the syntactic environment of the transformer."
--
Alex