[plt-scheme] Does anyone use `set!' and `get!' patterns?

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Sun Mar 9 13:46:11 EDT 2008

On Sun, Mar 09, 2008 at 02:46:49PM +0000, Joe Wells wrote:
> "Sam TH" <samth at ccs.neu.edu> writes:
>
> > Currently, "plt-match.ss" and scheme/match (in v4) provide `set!' and
> > `get!' patterns, which bind mutators and accessors for the matched
> > locations, respectively. While these look clever, they complicated the
> > implementation of match, and don't seem to be used.  In particular,
> > I've searched the entire collections hierarchy, and they don't seem to
> > be used at all.  Given this, I'd like to remove the implementations.
> > Does anyone else use them in their code, or have any reason that they
> > would want to?
>
> ML has this feature in pattern matching (in SML a pattern like “ref x”
> dereferences a mutable cell and binds its current contents to x).  So
> presumably PLT can claim to implement a superset of ML pattern
> matching.  Without this feature, ML fanboys could say “but you don't
> have mutator patterns, so our language is better, ha ha ha”.

If you follow the standard convention that ML's ref cells are equivalent to
PLT's boxes, then you can do the kind of match that you describe without
`get!' and `set!' patterns:

    [perdita:~]$ mzscheme
    Welcome to MzScheme v372 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
    > (require (lib "match.ss"))
    > (match (box 3)
        [#&x x]
        [else #f])
    3

I assume this behavior is still available in v4, but I haven't yet upgraded
and so don't really know what the equivalent to (require (lib "match.ss"))
is.

Richard


Posted on the users mailing list.