unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Update of pcase docs for the elisp manual
Date: Sun, 24 Jan 2016 18:17:10 -0500	[thread overview]
Message-ID: <jwva8nu1sve.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: 83io2j3v4v.fsf@gnu.org

>> 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.


Agreed.

>> >   . 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.


        Stefan




  reply	other threads:[~2016-01-24 23:17 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m2fuxq6pb0.fsf@newartisans.com>
     [not found] ` <87d1stznc6.fsf@web.de>
     [not found]   ` <m2si1p8r31.fsf@newartisans.com>
     [not found]     ` <m2powt5w50.fsf@newartisans.com>
2016-01-23 11:17       ` Update of pcase docs for the elisp manual Eli Zaretskii
2016-01-24  4:40         ` Stefan Monnier
2016-01-24 14:33           ` Eli Zaretskii
2016-01-24 23:17             ` Stefan Monnier [this message]
2016-01-25 16:14               ` Eli Zaretskii
2016-01-26  1:40                 ` Stefan Monnier
2016-01-26 15:38                   ` Eli Zaretskii
2016-01-26 16:23                     ` Stefan Monnier
2016-01-25 14:22             ` Michael Heerdegen
2016-01-25 14:15         ` Michael Heerdegen
2016-01-25 16:33           ` Eli Zaretskii
2016-01-28 18:37             ` Michael Heerdegen
2016-01-29  3:06               ` Stefan Monnier
2016-01-29  9:45               ` Eli Zaretskii
2016-01-29 14:51                 ` Michael Heerdegen
2016-01-26 16:59         ` John Wiegley
2016-01-26 18:10           ` Stefan Monnier
2016-01-26 18:41           ` Eli Zaretskii
2016-01-26 19:35             ` John Wiegley
2016-01-26 20:28               ` Eli Zaretskii
2016-01-29  1:28                 ` John Wiegley
2016-01-29  8:30                   ` Eli Zaretskii
2016-01-29 13:39                     ` Andy Moreton
2016-01-29 14:21                       ` Eli Zaretskii
2016-01-29 15:14                         ` Andy Moreton
2016-01-29 15:37                           ` Eli Zaretskii
2016-01-26 19:58             ` Andy Moreton
2016-01-26 20:19               ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwva8nu1sve.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).