[plt-scheme] match question

From: Sam TH (samth at ccs.neu.edu)
Date: Sun May 11 22:37:43 EDT 2008

The general answer is the all ... patterns are greedy, but in order,
from left to right.

So we match as many elements to `x' as possible, then one to `y', then
as many to `z' as possible, then another to the second `y'.

In the particular case, we match as many elements to `x' as possible,
while allowing the whole pattern to match.  That's the first 3
elements, and the fifth element gets matched to `z'.  In your second
example, we have to match at least two elements to `z', so we only
match 2 to `x'.

Does that help explain things?

sam th

On Sat, May 10, 2008 at 6:52 PM, praimon <praimon at gmail.com> wrote:
> hello,
>  in 3.99.0.24, using scheme/match:
>
>  (map (lambda (x)
>        (match x ((list x ... y z ..1 y) (append x z))))
>      '((1 2 3 4 3)
>        (1 2 3 4 3 4)
>        (1 2 3 4 3 3)))
>
>  => ((1 2 4) (1 2 3 3) (1 2 3 3))
>
>  I understand the first two matches, but
>  shouldn't the last result be (1 2 4 3)?
>
>  This produces my expected answer:
>
>  (match '(1 2 3 4 3 3)
>        ((list x ... y z ..2 y) (append x z)))
>
>  => (1 2 4 3)
>
>  but in this context, aren't ..1 and ..2 equivalent?
>
>  thanks,
>  praimon
>  _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.