[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pcase and minus-sign
From: |
Michael Heerdegen |
Subject: |
Re: pcase and minus-sign |
Date: |
Wed, 30 Nov 2016 16:34:08 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
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.
- pcase and minus-sign, Andreas Röhler, 2016/11/30
- Re: pcase and minus-sign, Joost Kremers, 2016/11/30
- Re: pcase and minus-sign, Andreas Röhler, 2016/11/30
- Re: pcase and minus-sign, Michael Heerdegen, 2016/11/30
- Re: pcase and minus-sign, tomas, 2016/11/30
- Re: pcase and minus-sign, Joost Kremers, 2016/11/30
- Re: pcase and minus-sign, Andreas Röhler, 2016/11/30
- Re: pcase and minus-sign,
Michael Heerdegen <=
- Re: pcase and minus-sign, Joost Kremers, 2016/11/30