public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
Cc: kawa mailing list <kawa@sourceware.org>
Subject: Re: unrecognized pattern operator list
Date: Tue, 10 Oct 2023 07:33:08 +0200	[thread overview]
Message-ID: <CADEOadfVRUN+_8yv2QZd01kUTv45K5z-jUry1ZTvxkrFaLtJbA@mail.gmail.com> (raw)
In-Reply-To: <CADEOaddzUGXT-1SB+SWC7jmp1oKxPmxCmquQzA2MEecPbHF8jw@mail.gmail.com>

i use 'match' for Kawa like this in my code, i haven't test it yet but
i suppose it is ok ,having done multiple test in the Kawa REPL :

(match (list index1-or-keyword-eval-pos index2-or-keyword-eval-pos)

     ;;  {a <+ (make-vector 7 0)}
     ;; '#(0 0 0 0 0 0 0)
     ;; > {a[$ $] <- #(1 2 3)}
     ;; > a
     ;; '#(1 2 3 0 0 0 0)
                    ;((list (== slice) (== slice))
     ([s1 s2] #!if (and (equal? s1 slice) (equal? s2 slice))
      (container-copy! container-eval
               0
               expr-eval)
      container-eval  ;; returning a value allow the chaining : {T[3 5
6] <- A[4 2 3] <- T[7 2 4]}
      )

     ;;  {s <+ (string-append "abcdefgh")}
     ;; "abcdefgh"
     ;; > {s[3 $] <- "zob"}
     ;; > s
     ;; "abczobgh"
     ;; >
     ([i1 s] #!if (equal? s slice)
      (container-copy! container-eval
               i1
               expr-eval)
      container-eval  ;; returning a value allow the chaining : {T[3 5
6] <- A[4 2 3] <- T[7 2 4]}
      )

     ([s i2] #!if (equal? s slice)
      (container-copy! container-eval
               0
               expr-eval
               0
               i2)
      container-eval  ;; returning a value allow the chaining : {T[3 5
6] <- A[4 2 3] <- T[7 2 4]}
      )

     ([i1 i2]
      (cond ((vector? container-eval)  ;; normal case
         (function-array-n-dim-set! container-eval expr-eval (reverse
(list i1 i2))))
        ((array? container-eval)
         ;;(display "assignment.* : 2 args ,array case :
container-eval = ") (display container-eval) (newline)
         (array-set! container-eval index1-or-keyword-eval
index2-or-keyword-eval expr-eval))

        (else ;; overloaded
         (define args-lst (list container-eval i1 i2))
         (define setter! (find-setter-for-overloaded-square-brackets args-lst))
         (setter! container-eval i1 i2 expr-eval)))
      expr-eval) ;; returning a value allow the chaining : {T[3 2] <-
A[4] <- T[2 4]}

     ) ;; end match

i can not find another way than:

#!if (and (equal? s1 slice) (equal? s2 slice)

to test equality to '($ $) or (list slice slice) , that does not look
like a pattern and i could have use 'cond' instead of 'match' as there
is little gain in syntax here.

On Mon, Oct 9, 2023 at 11:07 PM Damien Mattei <damien.mattei@gmail.com> wrote:
>
> GRASP ,amazing code , would be wonderful for teaching.
>
> On Mon, Oct 9, 2023 at 10:26 PM Panicz Maciej Godek
> <godek.maciek@gmail.com> wrote:
> >
> > For what it's worth, I wrote my own implementation of match for Kawa and use it in GRASP:
> >
> > https://github.com/panicz/grasp/blob/main/src/language/match.scm
> >
> > It is derived from the now withdrawn SRFI-200 document that I submitted at some point:
> >
> > https://srfi.schemers.org/srfi-200/srfi-200.html
> >
> > (it contains a fairly detailed description of the implementation of the match macro, both in syntax-case and syntax-rules)
> >
> > Anyway, it doesn't seem to be causing any conflicts with Kawa's built-in match, so you cloud try adapting it to your taste.
> >
> > pon., 9 paź 2023 o 22:18 Damien Mattei via Kawa <kawa@sourceware.org> napisał(a):
> >>
> >>      one of problem is coming from the special syntax of kawa that use
> >> [ ] where others scheme don't and incompatible with SRFI 105, this
> >> limits some use.
> >> like: in type[] or match with patterns looking like ([_ y] ...
> >> this would be a good idea to have an option in Kawa that allow
> >> replacing those [ ] by normal ( ) or even be compatible with the 2
> >> syntaxes should be possible
> >>
> >> in my case i dislike 'match form and do not using typing in scheme
> >> when available so this not a big problem in my codes but for now i do
> >> not know how to modify the SRFI-105 reader for be compatible. It is
> >> also possible to parse it with SRFI 105 and after modify again the
> >> code to set back the transformed [] in () again in [] in 'match and
> >> type[]  ....
> >>
> >>
> >> On Mon, Oct 9, 2023 at 4:48 PM Damien Mattei <damien.mattei@gmail.com> wrote:
> >> >
> >> > hello,
> >> >
> >> > in this code belonging from Guile and Racket version:
> >> >
> >> > (match (list index1-or-keyword-eval-pos index2-or-keyword-eval-pos
> >> > index3-or-keyword-or-step-eval-pos)
> >> >
> >> >
> >> >
> >> >
> >> >      ;;  {a <+ (make-vector 7 0)}
> >> >      ;; '#(0 0 0 0 0 0 0)
> >> >      ;; > {a[$ $] <- #(1 2 3)}
> >> >      ;; > a
> >> >      ;; '#(1 2 3 0 0 0 0)
> >> >      ((list (== slice) (== slice))
> >> >       (container-copy! container-eval
> >> >                0
> >> >                expr-eval)
> >> >
> >> > i have this error:
> >> > unrecognized pattern operator list near ((list (== slice) i2 (== slice))
> >> > slice is defined like that:
> >> >
> >> > (define $ '$)
> >> > (define slice $)
> >> >
> >> > what is the equivalent syntax for kawa?
> >> >
> >> > damien

  reply	other threads:[~2023-10-10  5:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 14:48 Damien Mattei
2023-10-09 20:18 ` Damien Mattei
2023-10-09 20:26   ` Panicz Maciej Godek
2023-10-09 21:07     ` Damien Mattei
2023-10-10  5:33       ` Damien Mattei [this message]
2023-10-10  6:44         ` Damien Mattei
2023-10-10  7:03           ` Damien Mattei
2023-10-11  7:25             ` Damien Mattei

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=CADEOadfVRUN+_8yv2QZd01kUTv45K5z-jUry1ZTvxkrFaLtJbA@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=kawa@sourceware.org \
    /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).