[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The poor state of documentation of pcase like things.
From: |
Michael Heerdegen |
Subject: |
Re: The poor state of documentation of pcase like things. |
Date: |
Sun, 27 Dec 2015 00:17:04 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Aaron Ecay <address@hidden> writes:
> Atoms (strings, numbers, and keywords) are simultaneously patterns and
> qpatterns. That is, one writes `(1 2) and not `(,1 ,2) to match a list
> containing 1 and 2 (though actually either form works). Why could _ not
> also be shared between the pattern and qpattern classes?
If you consider that ` quotes any element in its argument list unless it
is explicitly unquoted (that's how it actually works), an ATOM becomes
'ATOM, which is equivalent to just ATOM as a pattern.
That one can avoid the comma before atoms inside ` reflects that
equivalence on a different level.
There are more such analogies (for example `something and 'something are
equivalent if something doesn't include a comma) and it's good that they
are there, because it makes the grammar easier to memorize, aka "build a
mental model". Maybe you can call this "aesthetics" in this regard.
Making _ a qpattern would break the logic in the design: '_ matches the
symbol _, not anything as the _ pattern does (disjointness of
qpatterns and pcase patterns is a different thing, and I think nobody
cares about that).
Making _ a qpattern wouldn't break pcase, but it would make the thing
less consistent, because there would be a fracture somewhere in the
logic, e.g. if _ is a qpattern matching anything, `_ and '_ would have
different semantics as pcase patterns (the first would be equivalent to
_), or such things.
I would agree to do this anyway if there was a good reason. Saving a
comma or fitting the expectations of users that haven't yet completely
understood the semantics (I don't mean Phillip by that, I mean users who
want to learn the thing) is not a sufficing reason for obfuscating the
logic behind the design, I think.
Another thing is that I think, and that's what we want to emphasize in
the docs, that qpatterns are conceptually a different thing than pcase
patterns. Actually, the term "qpattern" has not much meaning at all, it
is only used as a helper to describe the grammar of ` (because it is
recursive, but actually, the grammar is very simple).
A qpattern is either an expression that is compared with equal, or a
placeholder for a real pattern via unquoting. That's all. If the
description of ` in pcase would be less formal and e.g. more like the
doc of `backquote', we probably would not even have a name for that.
Anyway, I think it's conceptually a bad thing to merge those two quite
different things.
Just my personal opinion of course. I've worked with pcase quite a lot
now. It took some time until I had internalized the concept (which is
why I think it's important to keep it simple). If others who have used
the tool quite regularly do think it would be a good idea to make _ a
qpattern, let's do it. But I think we should not hurry modifying a
thing in a way which at the first look seems like a good idea, and we
may regret later.
Sorry for the prose, this was more than you had asked for.
Regards,
Michael.
- Re: The poor state of documentation of pcase like things., (continued)
- Re: The poor state of documentation of pcase like things., Richard Stallman, 2015/12/24
- Re: The poor state of documentation of pcase like things., John Wiegley, 2015/12/24
- Re: The poor state of documentation of pcase like things., Richard Stallman, 2015/12/25
- Re: The poor state of documentation of pcase like things., Michael Heerdegen, 2015/12/25
- Re: The poor state of documentation of pcase like things., John Wiegley, 2015/12/25
- Re: The poor state of documentation of pcase like things., Richard Stallman, 2015/12/26
- Re: The poor state of documentation of pcase like things., Michael Heerdegen, 2015/12/26
- Re: The poor state of documentation of pcase like things., Aaron Ecay, 2015/12/26
- Re: The poor state of documentation of pcase like things.,
Michael Heerdegen <=
- Re: The poor state of documentation of pcase like things., Richard Stallman, 2015/12/26
RE: The poor state of documentation of pcase like things., Drew Adams, 2015/12/16
Re: The poor state of documentation of pcase like things., Phillip Lord, 2015/12/17
Re: The poor state of documentation of pcase like things., Michael Heerdegen, 2015/12/19
Re: The poor state of documentation of pcase like things., Eli Zaretskii, 2015/12/19