From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83548 invoked by alias); 20 Feb 2020 11:00:45 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 81863 invoked by uid 89); 20 Feb 2020 11:00:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f193.google.com Received: from mail-qk1-f193.google.com (HELO mail-qk1-f193.google.com) (209.85.222.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Feb 2020 11:00:37 +0000 Received: by mail-qk1-f193.google.com with SMTP id b7so3106285qkl.7 for ; Thu, 20 Feb 2020 03:00:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=XOEoNnyIuAFm4F0h5ZULceduqj6tRNb4XxGlXO4Gw18=; b=U2g6sQ2l1+dPDM96NJWLmArvKGqDRIfsg5DHwg9L+UIlwuePsN6H72bl6QGtyYq6LG 6rdbHakWjIK32I7cyLsA/t0a6U9TqD7+xwfI0ctLolBt0rgDWYbLiP3G25yRdNKN+EUl f+4WDgFO9/m8KribT6/9skQQmyVg/DV0rutZBN0fFtRSZa7DWjr1xP4cBKQN73qoOieM qsuTHKDSVqNguTcpy0SSX95LLvN+JklVeP3Xooi1ECpUlJhpGBPdomUiuta4SWckqUkC zsnW3UcZx8FWhWoX8foobGmC7wunE3AY75afSamHQZmFiG7tX30qhcKOdKm75vaLq/KF fwqw== MIME-Version: 1.0 References: <04256eab-fe24-417b-9f0d-fc554c9add96@www.fastmail.com> In-Reply-To: Reply-To: k.s.matheussen@notam02.no From: Kjetil Matheussen Date: Thu, 20 Feb 2020 11:00:00 -0000 Message-ID: Subject: Re: questions on libraries, pattern matching etc To: Duncan Mak Cc: Per Bothner , Ben , kawa mailing list Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2020-q1/txt/msg00020.txt 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 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 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.