[plt-scheme] The or-pattern in match.ss

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Mon Jan 6 15:22:37 EST 2003

Eli Barzilay wrote:

>  (The whole thing started with some small code I had
> which was expanded later to counter example the fact that ML is so
> great because some red/black tree code is so small...)

Perculiar. I was using match to translate Okasaki's ML code for
red-black trees.

> What I would really want to do is to have that code customizable so
> you can register more pieces of matching forms.  Then it would be
> simple to have modules register new patterns, like object systems
> etc.

This is a nice idea.

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?

It looks like Andrews does:

 (syntax-object->datum (expand '(match (list 1 2)
                                   [1      'foo]
                                   [(1 3) 'bar]
                                   [(1 2) 'baz])))

The code looks overall good, but the use of (#%app (lambda () 'foo) looks
inefficient.


NB: In the interaction window there is this nice snip for showing syntax. Is
it possible
     to make the left part wider. There ought to be room enough, the entire
snip
     occupies only halv a screen.
--
Jens Axel Søgaard




Posted on the users mailing list.