[plt-scheme] need examples on some macro patterns

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Apr 1 10:10:12 EDT 2009

On Apr  1, ying hu wrote:
> Hi,
> 
> When I was reading 11.1 of plt scheme reference, I can't understand the
> patterns below
>   | #(pattern ...)  | #(pattern ... pattern ellipses pattern ...)  | #s(
> key-datum pattern ...)  | #s(key-datum pattern ... pattern ellipses pattern
> ...)
> I tried to find some examples about these on google but I failed.
> Can someone give me some example on these patterns?


> (define-syntax foo
    (syntax-rules ()
      [(foo (x ...)) (list x ...)]
      [(foo #(x ...)) (list 'vec x ...)]
      [(foo #s(add x ...)) (+ x ...)]
      [(foo #s(mul x ...)) (* x ...)]))
> (foo (1 2 3 4))
(1 2 3 4)
> (foo #(1 2 3 4))
(vec 1 2 3 4)
> (foo #s(add 1 2 3 4))
10
> (foo #s(mul 1 2 3 4))
24

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.