[plt-scheme] Yet another cute idea

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Sep 30 14:21:49 EDT 2002

On Sep 30, Noel Welsh wrote:
> One of the nice things about match is that it allows
> pattern matching to use simple visual representations.
>  Because of its constrained applicability it isn't
> necessary to disambiguate lists from general sexps. 
> I'm not sure if your proposals will be as easy to use.
>  If it requires extra syntax then it may lose one of
> the main benefits (to me) of match.

I've managed to isolate the property that led me to be all excited
about it -- if you search for a meaning for (set! (foo x) blah), for
different `foo' identifiers, what would you do for `car'?  Obviously,
use `set-car!', and the same is true for other accessors of non-atomic
objects.  Now my thing seems like the obvious thing when I thought
about it, is that the motivation for transforming (set! (car x) y) to
(set-car! x y), is that you want later evaluations of the first form
`(car x)' to evaluate to the value of `y'.  Following this it is
simple to see that the obvious meaning of `(set! (list a b c) blah)'
would be to make later evaluations of `(list a b c)' to evaluate to
the value of `blah', which suggests deconstructing a list of three
values and assigning them to `a', `b', and `c'.  The fact that this
looks so obvious is basically the fact that I'm using the same form
for building a list and matching a list -- using a form with an
explicit `list' symbol.  This would not be possible with an implicit
list form since that will make (define (foo x) y) problematic -- does
it really mean (define (list foo x) y) or (define (#%app foo x) y)?

Oh, one thing I realized (and quickly added to Swindle) is that
`values' can only appear at the top level which basically means that
(define (values ...) ...) is a "short" form for `define-values', and
  (let ((x ...) ((values y z) ...)) ...)
translates to
  (let-values (((x) ....) ((y z) ...)) ...)
and the same for `set!'.

> Haskell has gone further than ML [...]

Also, what I realized is that those languages have no problem since
they always have an "explicit `list' symbol", just by parsing list

> http://research.microsoft.com/Users/simonpj/Papers/pat.htm
> [...]

Ugh, I'll be happy with atoms, lists and vectors to begin with...

> > 6. Finally, I want a simple way to extend the set of patterns, so
> >    you could just (import foo) and get more pattern keywords.

[Pfhhh...  That should have been `require'.]

> Now this is a tough one.  The modularity issues of
> composing languages are still an open research issue
> AFAIK.  Shriram's work on macros and micros should
> provide some inspiration.  I imagine the monadic
> interpreter guys also have something to say.  The Maya
> approach (multiple dispatch over syntax) may also be
> interesting.  

This part should actually be pretty easy using 200 -- all you need is
to hang pieces of information on syntax objects, then you can treat
them like any other symbol.  The best example is structures:

  => (define-struct foo (x y z))
  => foo
  => (require-for-syntax 'swindle/misc)
  => (define-syntax (bar stx)
       (printf ">>> ~s\n" (maptree syntax-object->datum
                                   (syntax-local-value #'foo)))
  => (bar)
  >>> (struct:foo make-foo foo? (foo-z foo-y foo-x)
       (set-foo-z! set-foo-y! set-foo-x!))

Actually, the conversion of `(set! (foo ...) ...)' to `(set-foo! ...)'
where the `set-foo!' identifier has the same context as `foo' is
similar to this too (and it makes highlighting in DrScheme works
nicely, which I wasn't even aware of).

On Sep 30, Noel Welsh wrote:
> Unfortunately I doubt it, cause I made it up.  I was
> trying to imagine what old geezer functional
> programmer might have used in the days of punch cards
> and the S & K combinators came to mind (ok,they
> probably used pencil and paper back then, but that
> isn't as evocative).

What I remembered are some white boards about 10x20cm with a grid of
holes, then I'd buy some chips with logic gates and wire things up
(then connect the whole thing to the RS232 at the back of my C64).  I
assumed that "patch boards" are reasonable English names for these
grids, and I definitely remember weird combination letters -- at least
S in CMOS, but that was so long I can't really remember if there was a
K somewhere....

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

Posted on the users mailing list.