On Wed, Nov 30 2016, Andreas Röhler wrote:
Thanks, that helps. Seems it relates to the following in docstring:
SYMBOL matches anything and binds it to SYMBOL.
Yup.
Now if I use some arbitrary char, like "a",
(defun foo (arg)
(interactive "P")
(pcase arg
(a (message "%s" "ARG was `a'"))
(1 (message "%s" "ARG was `1'"))
('- (message "%s" "ARG was minus-sign"))
(_ (message "%s" "ARG not minus-sign"))))
It picks that a-branch at any case - as documented but strange.
I don't think it's strange, TBH. `a' is essentially a let-bound
variable. Having the ability to bind values is extremely useful in
pcase, I'd say.
It may be a bit surprising that - functions the same way, but it's not
strange once you realise that - is not a special character in Lisp
(unlike most other programming languages). For example, the following
code works fine:
(let ((- "hi"))
(message "%s" -))
Note BTW that the same if true for the underscore: in your example, _
is also just a symbol used to let-bind some value. The only special
thing about _ is that the byte-compiler doesn't complain about an
unused variable if its name starts with an underscore. But again, the
following code works just fine:
(let ((_ "hi"))
(message "%s" _))