[Top][All Lists]

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

Re: Update of pcase docs for the elisp manual

From: Stefan Monnier
Subject: Re: Update of pcase docs for the elisp manual
Date: Sun, 24 Jan 2016 18:17:10 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

>> So (let (pred (lambda (x) (< 5 x))) (abs x)) ends up being equivalent to
>> (guard (< 5 (abs x))).
> Yes, because it doesn't use the feature for which 'let' was invented:
> it doesn't bind any symbols to values.  And that's the confusing part:
> 'let' is being used where it isn't really needed, so this is not the
> ideal example for the 'let' pattern.


>> >   . The exact syntax and possible forms of QPatterns are described
>> >     ambiguously and seemingly incompletely, and profoundly contradict
>> >     almost every given example of them.  Both Michael and the previous
>> >     manual text describe them as follows:
>> > 
>> >      The form is `QPAT where QPAT is one of the following:
>> > 
>> >        (QPAT1 . QPAT2)
>> >        [QPAT1 QPAT2 ... QPATn]
>> >        ,PAT
>> >        ATOM
>> > 
>> >     The last two look wrong: AFAIU, there is no QPattern of the form
>> >     `,PATH
>> I think `,PAT is a valid UPattern, which is simply equivalent to PAT.
>> >     or `ATOM.
>> And `ATOM is also a valid UPattern.
> The above describes QPatterns, not UPatterns.

Yes, the ` pcase-macro introduces a new kind of patterns (the
QPatterns) which are those that appear under the ` .

So when I say that `ATOM is a valid UPattern, it means that ATOM is
a valid QPattern.  And similarly when I say that "`,PAT is a valid
UPattern" it means that ",PAT" is a valid QPattern.

The QPattern and UPattern languages are not mutually exclusive: you
can't tell by looking at a pattern if it's a QPattern or a UPattern.
Instead, the context (whether it's within a ` or not) determines which
of the two is expected.

>> Of course it does: `(A B C D ...) is 100% equivalent to
>> `(A . (B . (C . (D . ...)))) and (QPAT1 . QPAT2) is a QPAT.
> Which IMO means we must add the likes of `(A B C D) to the manual,
> because expecting the readers of software documentation to solve
> riddles as they read is not a good idea.

Agreed.  Not needed for the docstring (which is more meant as
a reference for people who already know how it works, and needs to be
both exhaustive and concise), but useful for the manual.

>> >   . Last, but not least: NEWS says we now have a new UPattern 'quote',
>> >     but neither John, nor Michael or the doc strings mention this
>> >     pattern.  What did I miss?
>> The docstring says:
>> 'VAL          matches if the object is ‘equal’ to VAL.
>> and 'VAL is also spelled (quote VAL).
> This probably means that 'quote' shouldn't be documented as a separate
> pattern, as that is a technicality which is much more likely to
> confuse than to help understanding.

Just like the (A B C) vs (A . (B . (C . nil))) issue, 'A is one and the
same as (quote A), so it's definitely not a separate pattern.  The NEWS
file used the term "quote" because I find it clearer to talk about "the
`quote' pattern" than "the ' pattern".

> Unless, that is, there are important scenarios where using (quote FOO)
> in a pattern is required where it isn't a trivial replacement
> for 'FOO.

A macro (such as pcase) can never distinguish 'A from (quote A) since
the reader returns exactly the same result either way.


reply via email to

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