[plt-scheme] Yet another cute idea

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Sep 27 20:25:56 EDT 2002

After looking into match.ss, I think that there are more and more
things that make it the wrong solution -- at least for what I want.
Some of the problems that I've seen are:

1. I want the minimum weight at run time --
     (match-define (x y) (list a b))
   should roughly translate to something like
     (define-values (x y)
       (let ((x (list a b))) (... (values x1 x2) ...)))
   and the same for others (like match-lambda).

2. I want to be able to use the *same* patterns for `define', but
   still keep the current short form for functions.

3. I want also to be able to replace `lambda' with something that uses
   patterns, so any standard lambda expression will still behave the
   same (and translate to a simple lambda so there's no run-time
   cost), but I also want it to work with patterns so you could do
     (lambda (x (list y z)) ...)
   This is very far from what you get from match-lambda.

4. I want this to be a mechanism that will handle things like
   &optional and &key so they'd work for both lambda arguments and
   general matching.  This means that defining a function wraps its
   arguments in an implicit `list' pattern, and the initial
   destructuring is done by the function call so there is no run-time
   price.

5. I want all this to work with the other forms -- `let's, `set!', in
   the same way, but still allow `set!' to do generic setting.

6. Finally, I want a simple way to extend the set of patterns, so you
   could just (import foo) and get more pattern keywords.  This could
   be used for structs but also for any other arbitrary form you
   want.  The only requirement is that you supply the pieces of syntax
   that will check & destructure input values, and a function to
   assemble them back (since pattern keywords should be usable both as
   patterns and as construtors).

I don't know if satisfying all of this is possible, but one thing is
certain -- the main problem comes from the fact that parens are used
both for function application and as a datatype.  I think that always
using a syntactic keyword that looks like the constructor should solve
this, even if a little more verbose.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.