[plt-scheme] Problem with define-syntax. It is still not clear.
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))
=> (1 3)
=> #f
(define x '(1 3))
(testListe x)
=> (1 3)
=> #f
-----Message d'origine-----
De : plt-scheme-bounces at list.cs.brown.edu [
<mailto:plt-scheme-bounces at list.cs.brown.edu>
mailto:plt-scheme-bounces at list.cs.brown.edu] De la part de Chongkai Zhu
Envoyé : 19 janvier, 2006 00:30
À : plt-scheme
Objet : Re: [plt-scheme] Problem with define-syntax
======= At 2006-01-18, 19:57:10 Andre Mayers wrote: =======
>Good day
>
>I miss something which is surely basic.
>How can I define a macro that will match a list ?
>Why the following is not working ?
>
>(define-syntax testListe
> (syntax-rules ()
> [(_ (1 3)) #t]
> [(_ xxx) #f]))
>
>
>(define x '(1 3))
>(testListe x)
>
>Thank you
>
>Andre Mayers, Ph.D., professeur | tel: 819-821-8000x2041
>Departement d'informatique | fax: 819-821-8200
>Universite de Sherbrooke | andre.mayers at usherbrooke.ca
>Sherbrooke (Quebec) | <http://www.dmi.usherb.ca/~amayers>
http://www.dmi.usherb.ca/~amayers
>Canada J1K 2R1
>
You are trying to match (quote (1 3)) with (1 3).
> (testListe (1 3))
#t
-
Chongkai
_________________________________________________
For list-related administrative tasks:
<http://list.cs.brown.edu/mailman/listinfo/plt-scheme>
http://list.cs.brown.edu/mailman/listinfo/plt-scheme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060119/e7e5be00/attachment.html>