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

From: Jos Koot (jos.koot at telefonica.net)
Date: Sat Nov 28 14:45:17 EST 2009

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 
Now quote is a keyword and is not bound.

----- Original Message ----- 
From: "Skeptic ." <skeptic2000 at hotmail.com>
To: <plt-scheme at list.cs.brown.edu>
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 $ – é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

Posted on the users mailing list.