[plt-scheme] The or-pattern in match.ss
On Jan 6, Jens Axel Søgaard wrote:
> Perculiar. I was using match to translate Okasaki's ML code for
> red-black trees.
Not too peculiar. It's one of the classical things that annoy me:
someone showing how cool some language is by providing some example
which is very small and simple only because it uses patterns. Haskell
usually has such introductions. (BTW, something I'd really want to
implement is that nice list comprehension thing as a convenient
combination of map & filter possibly on multiple lists, the
implementation should be fun, but I can't think of any reasonable
syntax for it.)
> I was wondering about the method of implementation, do you
> collapse the test for the different patterns?
>
> I.e. in
>
> (match (list 1 2)
> [1 'foo]
> [(1 3) 'bar]
> [(1 2) 'qaz])
>
> will the test for testing the second and third pattern share code?
No. My code can use more improvements like this one (which shouldn't
be that hard -- it can be done as a simple post-processing step),
still, I believe it is a better start.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!