Discussion:
‘match’ and ‘!’ features
Mathieu Lirzin
2018-09-06 16:02:32 UTC
Permalink
Hello,

I am getting interested in using Kawa lately. I am happy to discover
that it implements pattern matching using the ‘match’ and ‘!’ macros.
However I am a bit puzzled by the fact those features are added in the
main module while the documentation on patterns [1] describe those
features as work in progress.

In order to lower the retro-compatibility expectations for those
experimentations, What do you think of moving the ‘match’ and ‘!’
definitions in a dedicated library for example (kawa match) ?

[1] https://www.gnu.org/software/kawa/Variables-and-Patterns.html
--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37
Per Bothner
2018-09-06 17:10:18 UTC
Permalink
Post by Mathieu Lirzin
Hello,
I am getting interested in using Kawa lately. I am happy to discover
that it implements pattern matching using the ‘match’ and ‘!’ macros.
However I am a bit puzzled by the fact those features are added in the
main module while the documentation on patterns [1] describe those
features as work in progress.
In order to lower the retro-compatibility expectations for those
experimentations, What do you think of moving the ‘match’ and ‘!’
definitions in a dedicated library for example (kawa match) ?
Moving these core features to library may be a bit of work, and
I don't think it would be desirable - as a core feature.
I'm reasonably comfortable with the syntax and design, and am not
planning on changing it. Of course there are almost certainly bugs as
well as under-optimized code.

The main feature where design and implementation are missing
is dealing with structural patterns.

Given a constructor function T, where T may be a type/class name
(see https://www.gnu.org/software/kawa/Allocating-objects.html),
what should be the pattern syntax for "destructuring"? The syntax

(T pat1 pat2 ... patN)

could be used to match a value created by (T e1 e2 ... eN)
by matching e1 against pat1 etc. There is a symmetry blemish in that T
in (T pat1 pat2 ... patN) is "evaluated" while the "arguments" are patterns,
but it still seems a reasonable syntax. Still, there are a number of
complications in doing this. Patterns with keyword arguments are slightly
easier. To match an obj against:

(T x: pat1 ... z: pat1)

could be implemented by matching obj:x against pat1 etc. In adddition
we should require (equal? obj (T obj:x ... obj:z)).

Then we could go further: Regular (tree) expressions. Strings.
XML/HTML nodes.

So that's what I mean when I say this feature is a work-in-progress.
--
--Per Bothner
***@bothner.com http://per.bothner.com/
Loading...