[plt-scheme] Trying to use match.ss
plt-scheme at fast.cs.utah.edu writes:
| You wrote the following on Wed, 28 May 2003 11:10:30 -0400
|
|| Welcome to MzScheme version 204, Copyright (c) 1995-2003 PLT
|| | (require (lib \"match.ss\"))
||
|| | (match \'(2 2 2 3) ((a ... 3 ...) #t))
|| #t
|| | (match \'(2 2 2 3) ((a ... 3) #t))
|| match: no matching clause for (2 2 2 3):
|| (match (quote (2 2 2 3)) ((a ... 3) #t))
|
| This occurs because the match is \"greedy\" and not pre-emptive.
| Since the pattern-variable _a_ will match anything, so _a ..._ alone matches the whole list.
Aha, I did realize that the matching was greedy but I thought it
back-tracked on failure. Thanks.
So I guess the way to match "a list with X anywhere in it" is
((not X) ... X _ ...)
? That could get a little painful when X gets complicated, since I
either have to duplicate it, or refactor it out of the match. When I
get the sources I will try
(list-no-order X _ ...)
although I don't know if that is an abuse of that construct or if it
is meant to be used that way.
Dan
--
http://www.dfan.org