all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: Artur Malabarba <bruce.connor.am@gmail.com>, 20784@debbugs.gnu.org
Subject: bug#20784: 25.0.50; pcase documentation on t and nil
Date: Thu, 11 Jun 2015 15:18:28 +0200	[thread overview]
Message-ID: <87r3pitmcb.fsf@web.de> (raw)
In-Reply-To: <jwvmw07ndw9.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Wed, 10 Jun 2015 23:07:35 -0400")

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

> > SELFQUOTING matches itself. This includes keywords, numbers, and
> > strings.
>
> > However, that doesn't apply to t and nil, instead, they are covered by
> > the SYMBOL clause.
>
> I think the problem is in the wording: t and nil are neither keywords,
> nor numbers, nor strings, which is why they aren't treated as
> SELFQUOTING.  IOW the wording shouldn't say "including" but make it
> clear that these are the (currently) only accepted selfquoting entities.
> E.g. vectors (and friends) aren't considered as SELFQUOTING by
> pcase either.

Just an opinion from another user:

I think the semantic of SELFQUOTING is so non-obvious and non-intuitive
that it's not worth it to confuse people who learn pcase with it, for
the sake that it's more or less the same as the pattern 'VAL, or a
subset from it:

SELFQUOTING applies to some atomic expressions that eval to themselves,
to others not.  SELFQUOTING "matches itself", which again depends on the
kind of thing.  It doesn't always mean `eq' (as the wording "itself"
suggests), because strings don't just match only themselves but any
other `equal' string.  But it also doesn't mean "equal" because in the
case of numbers, comparison is done with `eq':

(pcase 5.0
  (5 5)
  (5.0 5.0))  => 5.0

The case of t is especially non-obvious; it's neither treated as
SELFQUOTING nor as SYMBOL, but as a pattern matching anything.  While
`t' meaning "applies always" makes sense in `cond', because there the
right sides are interpreted as booleans, it can be IMHO confusing to
beginners in pcase because it could make you think that pcase is about
booleans, but it's about pattern matching.  I found myself trying stuff
like

  (pcase expr
    ((and x (symbolp x)) (symbol-name x))),

maybe having the `t' pattern in mind?

And `nil' OTOH is different again.  It is not interpreted as "applies
never", but raises an error when used  ("applies never" could make
sense when the code is generated by a macro).

I think I would consider to trivialize the semantic, merging the
SELFQUOTING and 'VAL case.

I would remove the SELFQUOTING thing as it is now.  I would keep the
semantic of 'VAL as it is now, as it is perfectly clear.  To substitute
the SELFQUOTING thing, we could allow something like ATOM - which can be
any atomic expression that is not a symbol that can be bound - and make
it simply an abbreviation for 'ATOM.  (FWIW, unifying `ATOM and 'ATOM
would IMHO also be worth it; currently 'ATOM is compared always with
`equal', whereby `ATOM is compared with `equal' for strings and `eq'
else.  You can always use guard when you want a different comparison
predicate.)

I know that would all would break existing code, but it would make pcase
easier to understand and to learn.

Just my two cents.


Regards,

Michael.





  parent reply	other threads:[~2015-06-11 13:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 20:20 bug#20784: 25.0.50; pcase documentation on t and nil Artur Malabarba
2015-06-11  3:07 ` Stefan Monnier
2015-06-11 12:24   ` Artur Malabarba
2015-06-11 12:33     ` Michael Heerdegen
2015-06-11 15:23     ` Stefan Monnier
2015-06-11 13:18   ` Michael Heerdegen [this message]
2015-06-11 16:22     ` Stefan Monnier
2015-06-12 17:31       ` Michael Heerdegen
2015-06-16 16:43         ` Stefan Monnier
2015-06-11 16:34     ` Stefan Monnier
2015-06-12 17:36       ` Michael Heerdegen
2016-07-01  2:39         ` npostavs

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

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

  git send-email \
    --in-reply-to=87r3pitmcb.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=20784@debbugs.gnu.org \
    --cc=bruce.connor.am@gmail.com \
    --cc=monnier@IRO.UMontreal.CA \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.