[plt-scheme] Re: Problem with define-syntax. It is still not clear.

From: Andre Mayers (andre.mayers at usherbrooke.ca)
Date: Thu Jan 19 15:48:25 EST 2006

I have finally understood. 

Thank you very much 


Andre 
-----Message d'origine-----
De : plt-scheme-bounces at list.cs.brown.edu
[mailto:plt-scheme-bounces at list.cs.brown.edu] De la part de David Van Horn
Envoyé : 19 janvier, 2006 10:14
À : plt-scheme at list.cs.brown.edu
Objet : [plt-scheme] Re: Problem with define-syntax. It is still not clear.

Andre Mayers wrote:
> Hello
> 
> If you try the following code, it seems that the macro sees the list (1
> 3) in both case but fails to match. In both case x should be the list (1
> 3) and not (quote (1 3)). I don't understand why. I guess the answer is
> simple but I can't find it after a few hours.
> 
> Thank you
> 
> (define-syntax testListe
>   (syntax-rules ()
>     [(_ (1 3)) #t]
>     [(_ xxx)
>      (begin
>        (display xxx)
>        (newline)
>        #f)]))
> 
> 
> (let ((x (list 1 3)))
>   (testListe  x))

Perhaps the pattern matching facility for run-time values is better
suited for your needs?

(require (lib "match.ss"))

(define (testListe ls)
  (match ls
    [(1 3) #t]))

(let ((x (list 1 3)))
  (testListe  x))

=> #t

HTH,
David

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-scheme




Posted on the users mailing list.