Re: Extensibility (and the lack thereof)
Wolfgang Corcoran-Mathe 27 Oct 2020 19:38 UTC
On 2020-10-26 21:58 -0400, John Cowan wrote:
> On Mon, Oct 26, 2020 at 8:35 PM Felix Thibault <xxxxxx@gmail.com>
> wrote:n
>
> Wait, is this like (match (view-proc obj) pattern ...)) ?
> >
>
> That was my original idea, but now I think it's better to do it
> differently. I'm going to stick with -> for now, as I think it helps
> readability. Here's an example:
>
> (define-record-type <point>
> (make-point x y)
> point?
> (x point-x)
> (y point-y))
>
> (define (point-view pt)
> (if (point? pt)
> (values (point-x pt) (point-y pt))
> (values))
>
> (define p (make-point 10 20))
>
> (match p
> ((-> point? point-view 10 y)
> (+ y 1))) => 21
This looks very nice! Maybe this relates to Marc's point about tree
patterns, but it seems that we'd want to recursively bring the whole
power of the matcher to bear on the patterns appearing after
<view-proc>, so that complex structures can be matched without nested
matches. e.g., the pattern grammar would be extended in something like
the following manner:
pat :
⋮
| (-> predicate proc pat1 ... patN)
Apologies for the redundancy if this is what everyone was already
thinking.
--
Wolfgang Corcoran-Mathe <xxxxxx@sigwinch.xyz>
"Scientific theories are judged by the coherence they lend to our
natural experience and the simplicity with which they do so.
The grand principle of the heavens balances on the razor's edge
of truth." --Commissioner Pravin Lal (Sid Meier's Alpha Centauri)