[plt-scheme] match library for r6rs
At Fri, 09 May 2008 15:32:22 -0700, Derick Eddington wrote:
> > But using this library with DrScheme leads to following error message:
> >
> > match.ss:377:6: compile: bad syntax; function application is not
> > allowed, because no #%app syntax transformer is bound
>
> I think the reason for this error could be a bug in MzScheme's R6RS
> support. I think the macro experts here can tell us. I think the issue
> has to do with export levels of bindings. IIRC (rnrs) is supposed to be
> imported for phase `expand' by default. The problem can be reduced to
> this example, which only works in MzScheme if the (rnrs) library is
> explicitly imported for phase `expand':
>
> #!r6rs
> (import (for (rnrs) run #;expand))
>
> (define-syntax A
> (let ()
> (define-syntax B
> (syntax-rules () [(_ x) x]))
> (define (h)
> (B 1))
> (lambda (ignored)
> (h))))
>
> (write (A)) (newline)
>
> ERROR=>
>
> compile: bad syntax; function application is not allowed, because no #%
> app syntax transformer is bound in: (syntax-rules () ((_ x) x))
>
> Uncomment the `expand' in the import form, and it works.
The use of `syntax-rules' is in phase level 2 (i.e., expand time
relative to expand time). The `(rnrs)' language exports `syntax-rules'
at phase level 1 (= `expand'), but not 2.
A `(run .... expand)' import of `(rnrs)' fixes the problem, because it
shifts the phase level 1 export of `syntax-rules' to phase level 2.
Matthew