[plt-scheme] Algebraic patterns

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Oct 1 14:49:41 EDT 2002

On Oct  1, Paul Graunke wrote:
> I would have expected something like
>  (define `(x y) (list 1 2))
> or
>  (define `(,x ,y) (list 1 2))

Currently I hacked

  (define '(x y) (list 1 2))

to work, but I'm not really happy with it -- but I agree with you -- I
think that the second one above is much better.  To do that, I think
that the best thing would be to use the quasiquote expander itself and
use the result -- but only do this for quasiquotes or redefining
macros would not be possible...  (And I don't know if expand-once is
reliable enough for this.)

> Also,
>  (define (x y) (list 1 2)) 
> would be the same as
>  (define x (lambda (y) (list 1 2)))

It is, unless you wrote the above meaning that `x' is a meta variable
and that it should be true for all possible (identifier) values...

> It's a bit more clunky, but quote is the usual way to distinguish
> between using ()'s for application or lists.  Maybe a different
> default is needed?

I'm confused.  I think that the quasiquote thing should work in any
case -- even if you think that making (define (list x y) ...) not
redefine `list' is a bad choice, you might consider the same decision
limited to (define (quasiquote ...) ...) as a better one.  Or maybe
you mean add some `define*' form that will always look at patterns?
(Which is a bad name since the "*" doesn't do the same it does to
`let', but define-pattern is too verbose...)

(Apologies in advance for the weird grammar in the above paragraph...)

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

Posted on the users mailing list.