[plt-scheme] [scribble] syntax quasi/unquote
To make use `lambda' in the right-and side of a `define-syntax', it you
start with just `scheme/base' as in the default evaluator, then you
need to also require `(for-syntax scheme/base)':
@(define ex-eval (make-base-eval))
@interaction-eval[#:eval ex-eval (require (for-syntax scheme/base))]
@(let ([unsyntax 'hide])
@def+int[
#:eval ex-eval
(define-syntax FOO
(lambda (stx)
(syntax-case stx ()
((FOO val)
#`(+ 1 #,(+ 1 2))))))
(FOO 2) ])
At Thu, 29 Apr 2010 14:05:44 -0400, Eric Tanter wrote:
> > I thought that something like this might work
> >
> > (define-syntax-rule @INTERACTION[form ...]
> > @interaction[(eval:alts @#,SCHEMEBLOCK[form] form) ...])
> >
> > but the problem is that the first part o `eval:lats' must be an
> > element, instead of a block.
> >
> > So, here's a different idea. The `def+int', etc. forms recognize
> > `unsyntax' by its binding, so you can just shadow that binding, like
> > this:
> >
> > @(let ([unsyntax 'hide])
> > @def+int[
> > (define l
> > #`(#,(+ 1 2)))
> > #`(#,l)
> > ])
>
> it does not work with a macro, for instance
>
> #lang scheme
> (define-syntax FOO
> (lambda (stx)
> (syntax-case stx ()
> ((FOO val)
> #`(+ 1 #,(+ 1 2))))))
> (FOO 2)
> --> 4
>
> and:
>
> @(let ([unsyntax 'hide])
> @def+int[
> (define-syntax FOO
> (lambda (stx)
> (syntax-case stx ()
> ((FOO val)
> #`(+ 1 #,(+ 1 2))))))
> (FOO 2) ])
>
> gives
> eval:1:0: compile: unbound identifier in the transformer environment (and no
> #%app syntax transformer is bound) at: lambda in: (lambda (stx) (syntax-case
> stx () ((FOO val) (quasisyntax (+ 1 (unsyntax (+ 1 2)))))))
>
> === context ===
> /Applications/_Extra/Devel/PLT Scheme
> v4.2.5/collects/scheme/private/more-scheme.ss:158:2:
> call-with-break-parameterization
> /Applications/_Extra/Devel/PLT Scheme v4.2.5/collects/scheme/sandbox.ss:700:9:
> loop
>
> I get the same error if I shadow both unsyntax and quasisyntax.
>
> (side question: why having chosen the same escape characters for the @... than
> the ones for syntax objects?)
>
> Thanks,
>
> -- Éric