emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pcase ` meaning


From: Garreau\, Alexandre
Subject: Re: pcase ` meaning
Date: Tue, 30 Oct 2018 01:17:51 +0100
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-09-15, modified by Debian

On 2018/10/30 at 00:57, Michael Heerdegen wrote:
> "Garreau, Alexandre" <address@hidden> writes:
>
>> > You mean like (pred (equal val))?
>>
>> Oh indeed!  Still that defeat the purpose of pattern matching by
>> requiring non-pattern matching stuff.
>
> What in that pattern is non-pattern matching stuff?

guards, pred, etc. are “pattern” in pcase parlance, but aren’t
pattern-matching in general sense: they are only a (handy) extra way to
specify arbitrary conditions in the middle of a pattern matching, in
addition to matching the *pattern*, that is a structure that mimick what
we want to match.

>> The fact pcase is not strictly treating ` as standard lisp’s reader does
>> is only *adding* the the already existing confusion normal and standard
>> ` introduces in lisp.
>
> ` is a normal macro, it has nothing to do with the reader.  Apart from
> the ` reader macro, which pcase doesn't touch at all.

They share a name, that’s enough.  And to me it seems that this name
sharing is here to (incompletely / incorrectly) borrow some of the
semantics of the ` reader macro.

> What it does is to give ` different semantics inside patterns.  Like
> your `list' pattern gives new semantics to the symbol `list'.  Oh my.

It’s not arbitrary random semantics, it base on the knowledge people
might have of “`”, and of its use along with “,”.  List, at the
opposite, is pure pattern matching, since it is used as a list
constructor, look:

(pcase (list 1 2 3) ((list 1 2 3) t))

It just looks *exactely* the same.

(pcase (list 1 2 3) ((list a b c) (+ a b c)))

And here it’s *almost* the same, beside identifiers, to be bound.

While:

(pcase `(1 2 3) (`(1 2 3) t))

look the same, as well as:

(pcase `(a b c) (`(a b c) t))

But not:

(pcase `(1 2 3) (`(,a ,b ,c) (+ a b c)))

>> > For understanding the definition above note that ``' (synonymous for
>> > `backquote') is a (very normal) macro accepting one argument STRUCTURE,
>> > whereby we also have an abbreviating reader syntax
>> > `STRUCTURE == (` STRUCTURE).  We also have the reader syntax
>> > ,THING == (, THING).
>>
>> Indeed you’re right, but that doesn’t automagically explain to me how
>> does exactely work the “,” macro, as it stays context dependant, not
>> trivial, and to me, “,” meant either “eval” or “undo ‘`’” (the later is
>> nearer to the meaning used in pcase btw).
>
> (, is not a macro, btw)  Well, in pcase patterns it "means" something
> different.  As `and' means something different in `rx'.

Yes.  A different meaning for `and', is acceptable, and the first time I
saw a complain about it I also immediatly thought to `rx'.  But if `and'
meaning change is acceptable it’s because “and” is already a word of
english with an abstract, independant, general meaning per se.  While
“`” is almost never used as in lisp, except as *real* quotes, that
match, as in `' in TeX (or docstrings), or `` in shellscript.

> You very often say that you expected something different.  I dunno what
> I first expected, I read the docs to learn pcase, and it took 5 minutes.

I sometimes exagerate in reguard to pcase understandability: I find its
syntax confusive because it is actually inconsistent with
outside-pcase-world, and I’m a perfectionist (that’s a defect that can
be workaround, still).

I do that because, though I’m not fond of pattern matching, I do think
sometimes it’s handy, useful or even necessary, and then I’d like pcase
to be the most easily understandable by the most possible people.

> I think we can agree that we disagree - I just don't share your
> opinion.  The thing is designed in a way that it matches how some, but
> not all people, like to think about pattern matching.

Not that much I believe: you were enthusiast as well about the `var'
pattern, and I’m pretty sure (and guess I’m not the only one) than
borrowing some patterns from other lisps pattern matching facilities may
allow less confusing pcase usages, as you initially wanted.

The one I’d push the harder, and find the most important, is (a b c)
(not quoted) to match a list, when no `a' pattern is defined, as it is
done in schemes’ match, and the most naive and simple common-lisp match.
Here I know pcase, currently, refuse it, but I didn’t yet hear people
talk against it, but I may expect to be a minority to want this, or at
least not to be a majority wanting it, or to have some people (Stefan?)
against it.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]