[plt-scheme] [scribble] syntax quasi/unquote

From: Eric Tanter (etanter at dcc.uchile.cl)
Date: Sun May 2 16:15:41 EDT 2010

Hi,

FWIW, I found a solution (or rather, workaround) to support evaluation of macros that use #,/#`.

Use SCHEMEBLOCK for the typesetting part, and then for the evaluation do it "manually" by invoking the evaluator explicitly:
@(ex-eval '(define-syntax ...))

Because the program given to the evaluator is quoted, there is no conflict anymore.

-- Éric


On Apr 29, 2010, at 2:05 PM, 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_________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.