From: Michael Heerdegen <michael_heerdegen@web.de>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: Joost Kremers <joostkremers@fastmail.fm>,
Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: pcase and minus-sign
Date: Wed, 30 Nov 2016 16:34:08 +0100 [thread overview]
Message-ID: <87d1hddlsf.fsf@web.de> (raw)
In-Reply-To: <cabbb63b-f494-c804-4082-0aedc7dc52b8@easy-emacs.de> ("Andreas \=\?utf-8\?Q\?R\=C3\=B6hler\=22's\?\= message of "Wed, 30 Nov 2016 16:23:57 +0100")
Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
> But what make the char `a' so special WRT char `1'?:
>
> (defun foo (arg)
> (interactive "P")
> (pcase arg
> (1 (message "%s" "ARG was `1'"))
> (a (message "%s" "ARG was `a'"))
> ('- (message "%s" "ARG was minus-sign"))
> (_ (message "%s" "ARG not minus-sign"))))
The Lisp reader maps "a" to a symbol, but "1" to an integer. As pcase
patterns, symbols and integers have a different meaning.
If pcase could only match against atoms, this would be strange. But
pcase is not `case', and as already has been mentioned, being able to
use variables in patterns (for binding or equivalence tests) is very
useful.
If you want to test whether your ARG is `equal' to some VALUE, you can
always use 'VALUE as pattern. This is very consistent and easy to
remember. Anything not quoted has a different meaning as a pattern.
There is one exception: if VALUE is actually a keyword, an integer, or a
string, you can omit the quote (as you do above for "1") - but you don't
need to omit it. Symbols that are not keywords are not included in this
list, because they already have a different meaning.
Michael.
next prev parent reply other threads:[~2016-11-30 15:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-30 12:12 pcase and minus-sign Andreas Röhler
2016-11-30 12:38 ` Joost Kremers
2016-11-30 13:30 ` Andreas Röhler
2016-11-30 13:31 ` Michael Heerdegen
2016-11-30 13:39 ` tomas
2016-11-30 13:56 ` Joost Kremers
2016-11-30 15:23 ` Andreas Röhler
2016-11-30 15:34 ` Michael Heerdegen [this message]
2016-11-30 15:48 ` Joost Kremers
2016-12-01 13:59 ` Andreas Röhler
2016-12-02 2:30 ` Stefan Monnier
2016-12-03 8:04 ` Andreas Röhler
2016-12-03 15:43 ` Stefan Monnier
2016-12-05 9:11 ` Andreas Röhler
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=87d1hddlsf.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=andreas.roehler@easy-emacs.de \
--cc=help-gnu-emacs@gnu.org \
--cc=joostkremers@fastmail.fm \
/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.