[plt-scheme] binding in template

From: jos.koot at tiscali.nl (jos.koot at tiscali.nl)
Date: Fri May 12 10:17:45 EDT 2006

Thanks, 
I read the relevant parts of srfi 72. Its clear and convincing. I'll 
stick to the use of #'y in order to avoid problems in more complicated 
code (which my simple example was derived from)
PLT is great, Jos Koot

----Oorspronkelijk bericht----
Van: mflatt at cs.utah.edu
Datum : 12/05/2006 14:38
Aan: "jos.koot at tiscali.nl"<jos.koot at tiscali.nl>
Cc: <plt-scheme at list.cs.brown.edu>
Onderw: Re: [plt-scheme] binding in template

At Fri, 12 May 2006 11:07:32 +0200 (CEST), "jos.koot at tiscali.nl" 
wrote:
> ;Hi, From the example below it seems that in the template of a 
syntax-
> case rule not only pattern variables are pattern-bound, but also 
> variables introduced in binding positions within the template 
itself. 
> This is most convenient. Can it be trusted to work in general? 
> Greetings, Jos koot.
> 
> (define-syntax (monkey stx)
>  (define (gen-expr x y) #`(list #,x #,y))
>  (syntax-case stx ()
>   ((monkey x) #`(let ((y 0)) #,(gen-expr #'x #'y)))))

In this example, #'y isn't pattern-bound. The code would work if you
wrote it like this:

 (define-syntax (monkey stx)
  (define (gen-expr x) #`(list #,x y))
  (syntax-case stx ()
   ((monkey x) #`(let ((y 0)) #,(gen-expr #'x)))))

In both cases, the macro works because all of the #'y are introduced 
by
the same macro invocation, and so both `y's refer to the same binding.

Your original definition is probably better, because it keeps the two
introductions of `y' close together. In fact, there's some debate on
whether my revision should have worked; see SRFI 72 for a slightly
different macro system where your original definition works and my
revision doesn't (because the two `y's are in different quasisyntax
forms).

Matthew








Posted on the users mailing list.