[plt-scheme] Another syntax issue
> Welcome to MzScheme version 200, Copyright (c) 1995-2002 PLT
> > (module foo mzscheme (provide bar) (define (bar stx) (syntax-case stx
> () ((_ a) #'(list a)))))
> > (require-for-syntax foo)
> > (define-syntax baz bar)
> > (baz 1)
> STDIN::81: compile: bad syntax; function application is not allowed,
> because no #%app syntax transformer is bound in: (list 1)
>
> I can sort of understand why this happens: module foo is defined at
> stage 1, and the syntax objects generated in it refer to stage 0, which
> has not been defined at all for this instance of foo and is thus empty.
> Right?
Right.
> What I can't figure out is how to fix the problem.
You need the opposite of `require-for-syntax' --- something that
imports bindings into phase -1 instead of +1. But it doesn't yet exist
(and it's another feature planned for the next iteration).
I've worked around this problem in my code by writing functions like
`bar' to take a syntax object for context. Every literal then has to be
explicitly constructed, which is certainly a pain. In practice, instead
of writing
(syntax (list 1))
I write
(datum->syntax-object ctx-stx '(list 1))
where `ctx-stx' is the context-supplying syntax object.
Matthew