[plt-scheme] Trying to use match.ss

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed May 28 12:27:58 EDT 2003

Dan Schmidt wrote:

> I'm having trouble understanding how ... works in match patterns.

I think there is a couple of documentation bugs in 204.
First figure 1 containing the syntax of patterns is missing.
Second in the text examples, one can not distinguinsh between
"..." standing for "insert patterns here", and the literal "...".

> Here are a couple of pairs of calls to match; in each case I don't
> understand why the first one works and the second one doesn't.
>
>   Welcome to MzScheme version 204, Copyright (c) 1995-2003 PLT
>   > (require (lib "match.ss"))
>
>   > (match '(2 2 2 3) ((a ... 3 ...) #t))
>   #t

I checked the above pattern on MzScheme 202, and it said bad match
clause.

I note that a literal "..." is not allowed anywhere but in the end of
a quasi-pattern - and by careful study of 21.1 I would say that the
pattern is not allowed according to the documentation.

I guess Bruce has extended the matcher, but forgot to document it.

But let us see how it matches:

   > (match '(2 2 2 3)
       [(a ... 3 ...) a])
   (2 2 2 3)

Thus the pattern 3 ... must match the empty list.

>   > (match '(2 2 2 3) ((a ... 3) #t))
>   match: no matching clause for (2 2 2 3):

If a matches (2 2 2 3) then 3 doesn't match the empty list.

>   > (match '(2 2 2 3) (((and (not 3) a) ... 3) a))
>   (2 2 2)

This is better. The (and (not 3) a) ... matches only (2 2 2).

>   > (match '(2 2 2 3) ((a ... 3) a))
>   match: no matching clause for (2 2 2 3):

The "a ..." matches (2 2 2 3) and the final 3 does not match the empty
list.


--
Jens Axel Søgaard




Posted on the users mailing list.