public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: Per Bothner <per@bothner.com>
Cc: Kawa <kawa@sourceware.org>
Subject: Re: match form as a generalization of case
Date: Mon, 23 Jan 2017 22:12:00 -0000	[thread overview]
Message-ID: <CADEOadf_cPxqk3iK8jmGuoo-Hffe1JUUNst33m91-44G-6UBig@mail.gmail.com> (raw)
In-Reply-To: <4509f53c-2941-4b1b-4935-e7b7bc5090a9@bothner.com>

thank you Per,
i will try this as soon as possible, if it is always build for jdk8 it
could be running because i must keep compatibility (and other people
are administering the sidonie2.oca.eu server and they want to keep the
server secure with only well tested package and they do not want to
have anything to recompile-sic)on the tomcat server with jdk8 (not 7
or 9), openjdk8 for debian,  and with bigloo that is compiled for
jdk8.
Also the pakckaging of kawa seems to have changed from .jar to .zip i
suppose i can extract it to create a jar file the way i already do it
with bigloo that provide.zip for the runtime lib, i must do that
because netbeans (and perheaps tomcat) only accept .jar files and zip
files are not recognized.I do not understand why switching from jar to
zip, seems to become general as it is more en more uncountered.
Damien

On Sun, Jan 22, 2017 at 5:35 AM, Per Bothner <per@bothner.com> wrote:
> I checked into the invoke branch a new 'match' form.
> (Actually, it was there before, but was broken.)
> I also checked some pattern extension to make match more useful, and
> documentation.
>
> If you want to try it out without re-building form git,
> you can try this:
> http://ftp.gnu.org/gnu/kawa/kawa-2.91_invoke-20170121.zip
>
> That zip file includes the documentation, which you can browse
> with the command:
>   kawa-2.91_invoke/bin/kawa --browse-manual
>
> Here are the highlights.  Note also that lambda and let forms
> both take PATTERNs now.
>
>  -- Syntax: match MATCH-KEY EXPRESSION MATCH-CLAUSE^{+}
>      The ‘match’ form is a generalization of ‘case’ using PATTERNs,
>           MATCH-KEY ::= EXPRESSION
>           MATCH-CLAUSE ::=
>             ‘(’ PATTERN [GUARD] BODY ‘)’
>      The MATCH-KEY is evaluated, Then the MATCH-CLAUSEs are tried in
>      order.  The first MATCH-CLAUSE whose PATTERN matches (and the
>      GUARD, if any, is true), is selected, and the corresponding BODY
>      evaluated.  It is an error if no MATCH-CLAUSE matches.
>           (match value
>             (0 (found-zero))
>             (x #if (> x 0) (found-positive x))
>             (x #if (< x 0) (found-negative x))
>             (x::symbol (found-symbol x))
>             (_ (found-other)))
>
>      One ‘case’ feature is not (yet) directly supported by ‘match’:
>      Matching against a list of values.  However, this is easy to
>      simulate using a guard using ‘memq’, ‘memv’, or ‘member’:
>           ;; compare similar example under case
>           (match (car '(c d))
>             (x #!if (memv x '(a e i o u)) ’vowel)
>             (x #!if (memv x '(w y)) ’semivowel)
>             (x x))
>
> 8.3.1 Patterns
> --------------
>
> The usual way to bind variables is to match an incoming value against a
> “pattern”.  The pattern contains variables that are bound to some value
> derived from the value.
>      (! [x::double y::double] (some-expression))
> In the above example, the pattern ‘[x::double y::double]’ is matched
> against the incoming value that results from evaluating
> ‘(some-expression)’.  That value is required to be a two-element
> sequence.  Then the sub-pattern ‘x::double’ is matched against element 0
> of the sequence, which means it is coerced to a ‘double’ and then the
> coerced value is matched against the sub-pattern ‘x’ (which trivially
> succeeds).  Similarly, ‘y::double’ is matched against element 1.
>
> The syntax of patterns is a work-in-progress.  (The focus until now has
> been in designing and implementing how patterns work in general, rather
> than the details of the pattern syntax.)
>
>      PATTERN ::= IDENTIFIER
>        | ‘_’
>        | PATTERN-LITERAL
>        | ‘’’DATUM
>        | PATTERN ‘::’ TYPE
>        | ‘[’ LPATTERN^{*} ‘]’
>      LPATTERN ::= PATTERN
>        | ‘@’ PATTERN
>        | PATTERN ‘...’
>        | GUARD
>      PATTERN-LITERAL ::=
>          BOOLEAN | number | CHARACTER | STRING
>      GUARD ::= ‘#!if’ EXPRESSION
>
> This is how the specific patterns work:
>
> IDENTIFIER
>      This is the simplest and most common form of pattern.  The
>      IDENTIFIER is bound to a new variable that is initialized to the
>      incoming value.
>
> ‘_’
>      This pattern just discards the incoming value.  It is equivalent to
>      a unique otherwise-unused IDENTIFIER.
>
> PATTERN-LITERAL
>      Matches if the value is ‘equal?’ to the PATTERN-LITERAL.
>
> ‘’’DATUM
>      Matches if the value is ‘equal?’ to the quoted DATUM.
>
> PATTERN ‘::’ TYPE
>      The incoming value is coerced to a value of the specified TYPE, and
>      then the coerced value is matched against the sub-PATTERN.  Most
>      commonly the sub-PATTERN is a plain IDENTIFIER, so the latter match
>      is trivial.
>
> ‘[’ LPATTERN^{*} ‘]’
>      The incoming value must be a sequence (a list, vector or similar).
>      In the case where each sub-pattern is a plain PATTERN, then the
>      number of sub-patterns must match the size of the sequence, and
>      each sub-pattern is matched against the corresponding element of
>      the sequence.  More generally, each sub-pattern may match zero or
>      more consequtive elements of the incoming sequence.
>
> ‘#!if’ EXPRESSION
>      No incoming value is used.  Instead the EXPRESSION is evaluated.
>      If the result is true, matching succeeds (so far); otherwise the
>      match fails.  This form is called a “guard”
>      (https://en.wikipedia.org/wiki/Guard_(computer_science)).
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

  reply	other threads:[~2017-01-23 22:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-17 10:07 behavior of CASE with strings PART 2 Damien MATTEI
2017-01-17 13:24 ` Per Bothner
2017-01-17 15:57   ` Jamison Hope
2017-01-18  6:37     ` Per Bothner
2017-01-19  4:53       ` Per Bothner
2017-01-19 10:04         ` Damien MATTEI
2017-01-19 16:00           ` Per Bothner
2017-01-21  9:47         ` Damien Mattei
2017-01-22  4:36           ` match form as a generalization of case Per Bothner
2017-01-23 22:12             ` Damien Mattei [this message]
2017-01-23 22:27               ` 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=CADEOadf_cPxqk3iK8jmGuoo-Hffe1JUUNst33m91-44G-6UBig@mail.gmail.com \
    --to=damien.mattei@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).