From: Kjetil Matheussen <k.s.matheussen@gmail.com>
To: Duncan Mak <duncanmak@gmail.com>
Cc: Per Bothner <per@bothner.com>, Ben <ben@srctxt.com>,
kawa mailing list <kawa@sourceware.org>
Subject: Re: questions on libraries, pattern matching etc
Date: Thu, 20 Feb 2020 11:00:00 -0000 [thread overview]
Message-ID: <CAC6niE+n1CowT1JY5=x0iY-GOP27KArT_qGod=TOLYYVi4e+=Q@mail.gmail.com> (raw)
In-Reply-To: <CABgWrqoooE3tVOX36gYkF1AarEf-a3_HRftqu6ppetTw=wyxSQ@mail.gmail.com>
I made this one a few years ago, which I think is pretty good:
https://github.com/kmatheussen/fedex2
I've used it a lot too, so it's well tested:
https://github.com/kmatheussen/radium/tree/master/bin/scheme
(might be some improvements in this repo)
It should only contain plain r4rs/r5rs scheme code (or thereabout),
except for the define-match macro, which looks like this:
(define-macro (define-match funcname . matchers)
(create-matcher-func funcname matchers))
Example:
(define-match keep
[ ] ____ :> '[]
[A . Rest] Pred :> (cons A (keep Rest Pred)) :where (Pred A)
[_ . Rest] Pred :> (keep Rest Pred))
(define-match quicksort
[] :> '[]
[A . R] :> (append (quicksort (keep R (lambda (B) (>= A B))))
(list A)
(quicksort (keep R (lambda (B) (< A B))))))
On Wed, Feb 19, 2020 at 10:39 PM Duncan Mak <duncanmak@gmail.com> wrote:
>
> Hello Ben,
>
> Did you figure out a way to get a pattern match library to work with Kawa?
> Which one did you go with?
>
> I came across this recently, and I'm gonna give it a try:
> http://www.j-paine.org/match.html
>
> I don't have particularly sophisticated needs, I'm hoping to find something
> that will let me match on lists with some literals and some open slots, and
> it'll be great if I can define optional elements also.
>
>
> Duncan.
>
> On Sun, Dec 15, 2019 at 7:59 PM Per Bothner <per@bothner.com> wrote:
>
> > On 12/15/19 3:46 PM, Ben wrote:
> > > hi
> > > I'd like to test how I can use pattern match in Kawa. First I did try to
> > use Kawas pattern matching function, but from what I saw it is a bit
> > limited, for example there is no matching of lists.
> >
> > Actually, there is matching of lists, but by matching them as general
> > sequences:
> >
> > #|kawa:1|# (! [a b c @rest] [1 2 3 4 5 6])
> > #|kawa:2|# (format "a: ~a b: ~a c: ~a rest: ~a~%" a b c rest)
> > a: 1 b: 2 c: 3 rest: #(4 5 6)
> >
> > Implementing more general matching is mainly an issue of design including
> > deciding on a syntax.
> > Fundamentally, should be syntax for matching a pair be:
> >
> > (! (pat_car . pat_cdr) value)
> >
> > or:
> >
> > (! (cons pat_car pat_cdr) value)
> >
> > or something else?
> > The latter is used in Racket, and is more flexible, I believe, but not as
> > elegant -
> > which ties back to fundamental awkwardness with the Scheme evaluation
> > model.
> >
> > Of course once we/I decide on a syntax, then it needs to be implemented,
> > but
> > should be fairly straight-forward, given the existing framework.
> > --
> > --Per Bothner
> > per@bothner.com http://per.bothner.com/
> >
>
>
> --
> Duncan.
next prev parent reply other threads:[~2020-02-20 11:00 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 [this message]
2020-06-29 20:50 ` Duncan Mak
2020-06-29 21:49 ` Per Bothner
2020-06-30 4:38 ` Duncan Mak
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='CAC6niE+n1CowT1JY5=x0iY-GOP27KArT_qGod=TOLYYVi4e+=Q@mail.gmail.com' \
--to=k.s.matheussen@gmail.com \
--cc=ben@srctxt.com \
--cc=duncanmak@gmail.com \
--cc=k.s.matheussen@notam02.no \
--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).