public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Duncan Mak <duncanmak@gmail.com>
To: Per Bothner <per@bothner.com>
Cc: kawa mailing list <kawa@sourceware.org>
Subject: Re: questions on libraries, pattern matching etc
Date: Tue, 30 Jun 2020 00:38:34 -0400	[thread overview]
Message-ID: <CABgWrqoGqO2Lm+y3G1DBGhJg1tybaYF5vZdK4LucabMVKgo_tg@mail.gmail.com> (raw)
In-Reply-To: <81eb9fce-930a-f2b7-52ce-12f8da4c0be4@bothner.com>

Hello Per,

So I'm trying to really learn the Kawa pattern language, but I couldn't
figure out how to match a literal.

While it was encouraging to see that this seems to work:

#|kawa:17|# (match '(foo 1 2) ([foo a b] (+ a b)))
3


But not this:

#|kawa:18|# (match '(foo 1 2) (['foo a b] (+ a b)))
java.lang.NullPointerException


So how do I match against a form like '(foo x y) and make sure that the
first element of the list is the literal symbol 'foo?

Also, this is more akin to destructuring, but is there a way to use the
match macro against a record?

Thanks!


Duncan.

On Mon, Jun 29, 2020 at 5:50 PM Per Bothner <per@bothner.com> wrote:

> On 6/29/20 1:50 PM, Duncan Mak wrote:
> > Hello Per,
> >
> > About the syntax for a match macro, work on SRFI 200 (draft) just
> started:
> >
> > https://srfi.schemers.org/srfi-200/srfi-200.html
>
> I haven't read it in detail, but it looks like the proposed pattern syntax
> is more-or-less compatible with Kawa.
>
> (There are lots of SRFIs coming out, and I've given up trying to pay close
> attention, especially since may of them are philosophically incompatible
> with Kawa.  For example, Kawa has a consistent and powerful "sequence"
> concept and I think it's a mistake to define a large library of procedures
> for every sequence type, as seems to be the direction of R7RS-large.)
>
> The key thing about patterns in Kawa is they are integrated in the
> standard syntax forms, rather than being a pure "add-on" library feature.
> For example, the "variable" defined in a LET form can be a pattern.
>
> Also, not that in Kawa patterns and type-specifiers are integrated:  a
> PATTERN
> can be:
>    PATTERN ::TYPE
>
> To extend the syntax of Kawa patterns (which is highly deirable,
> and could plausible be done in the style of SRFI-200) one would need
> to extend kawa/lang/BindDecls.java, primarily.
> Not completely trivial, but not impossible either :-)
>
> > What do you think about adopting the syntax for the
> Wright-Cartwright-Shinn matcher?
> >
> > I've been trying to use match.scm (and its variants) in Kawa and simple
> patterns kinda work, but I see that:
> >
> > - matching records
> > - matching quasiquotes
> >
> > These two parts don't seem to be working.
> >
> > For now, I've backed out of using match.scm due to the missing features,
> but it'd really be nice to have a match macro that comes with Kawa scheme,
> following one of the grammar listed in the SRFI.
> >
> > Going a different direction, this design for a CASE* macro is also
> interesting,
> https://github.com/axch/pattern-case/blob/master/pattern-matching.txt
>
> While I'm OK with adding verious SRFI libraries for cmpatibility, patterns
> in
> the core part of Kawa should follow (and extend) the design in:
> https://www.gnu.org/software/kawa/Variables-and-Patterns.html#meta-pattern
> https://www.gnu.org/software/kawa/Definitions.html
> https://www.gnu.org/software/kawa/Local-binding-constructs.html
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/
>


-- 
Duncan.

  reply	other threads:[~2020-06-30  4:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-15 23:47 Ben
2019-12-16  0:59 ` Per Bothner
2020-02-19 21:39   ` Duncan Mak
2020-02-20 11:00     ` Kjetil Matheussen
2020-06-29 20:50   ` Duncan Mak
2020-06-29 21:49     ` Per Bothner
2020-06-30  4:38       ` Duncan Mak [this message]
2020-06-30  5:48         ` Per Bothner
2020-07-01  4:52         ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABgWrqoGqO2Lm+y3G1DBGhJg1tybaYF5vZdK4LucabMVKgo_tg@mail.gmail.com \
    --to=duncanmak@gmail.com \
    --cc=kawa@sourceware.org \
    --cc=per@bothner.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).