[plt-scheme] Not getting a tricky match right: possible?

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Feb 12 09:57:18 EST 2008

On Feb 12, Andrew Reilly wrote:
> Hi there,
> 
> Here's a match question, prompted by a recent c.l.l post:
> 
> Why doesn't this expression:
> (match '(1 1 (f a) 2 3 y (f 8) 9 (f 10))
>        ((list (and _ (list 'f x)) ...) x))
> return
> (a 8 10)?
> 
> (It breaks because there is no matching clause.)
> 
> I thought that the (and _ foo) would ensure that at least
> something would match (and be discarded).

It requires *both* to match.  Using `or':

  (match '(1 1 (f a) 2 3 y (f 8) 9 (f 10))
    ((list (or _ (list 'f x)) ...) 111))

works, but then you don't get to use `x'.  (Which makes sense.)

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


Posted on the users mailing list.