[plt-scheme] syntax-case + quote as a pattern variable

From: Skeptic . (skeptic2000 at hotmail.com)
Date: Sat Nov 28 14:58:58 EST 2009


Of course (the litterals list)!

Thanks.
----------------------------------------
> From: jos.koot at telefonica.net
> To: skeptic2000 at hotmail.com; plt-scheme at list.cs.brown.edu
> Subject: Re: [plt-scheme] syntax-case + quote as a pattern variable
> Date: Sat, 28 Nov 2009 20:45:17 +0100
>
> Rather simple, I think.
> (define-syntax test (¦Ë (stx) (syntax-case stx () [(t 'x) (with-syntax ([id (datum->syntax (syntax t) 'id) ]) #' (define id x))])))
> is equivalent with
> (define-syntax test (¦Ë (stx) (syntax-case stx () [(t (quote x)) (with-syntax ([id (datum->syntax (syntax t) (quote id)) ]) #'
> (define id x))])))
> which means that identifier quote is bound to a syntax. You can try:
> (define-syntax test (¦Ë (stx) (syntax-case stx (quote) [(t 'x) (with-syntax ([id (datum->syntax (syntax t) 'id) ]) #' (define id
> x))])))
> Now quote is a keyword and is not bound.
> Jos
>
> ----- Original Message -----
> From: "Skeptic ." 
> To: 
> Sent: Saturday, November 28, 2009 8:30 PM
> Subject: [plt-scheme] syntax-case + quote as a pattern variable
>
>
>>
>>
>> Hi,
>> I recently faced the situation where I wanted to both have a quote in the pattern and to create a non-hygienic identifier using
>> datum->syntax in a syntax-case, I got the following error : the pattern variable "quote" cannot be use in this context.
>> A minimal example :
>> (define-syntax test (¦Ë (stx) (syntax-case stx () [(t 'x) (with-syntax ([id (datum->syntax (syntax t) 'id) ]) #' (define id x))])))
>>>(define x 4)>(test 'x)>id
>> My solution was to bind the symbol in a let before the syntax-case :
>> (define-syntax test (let ([s 'id]) (¦Ë (stx) (syntax-case stx () [(t 'x) (with-syntax ([id (datum->syntax (syntax t) s) ]) #'
>> (define id x))]))))
>>
>> I'm curious to hear what syntax-case experts have to say about it.
>> Thanks.
>> _________________________________________________________________
>> Obtenez Windows 7 pour aussi peu que 39,99 $ ¨C ¨¦tudiants d¡¯¨¦tablissements coll¨¦giaux et universitaires canadiens seulement. L¡¯offre
>> prend fin le 3 janvier : achetez-le maintenant!
>> http://go.microsoft.com/?linkid=9691829
>
>
> --------------------------------------------------------------------------------
>
>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>
>
 		 	   		  
_________________________________________________________________
Windows Live : informez vos amis de vos activit¨¦s en ligne.
http://go.microsoft.com/?linkid=9691825


Posted on the users mailing list.