|
From: | Andreas Röhler |
Subject: | Re: pcase and minus-sign |
Date: | Wed, 30 Nov 2016 14:30:11 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Icedove/45.4.0 |
On 30.11.2016 13:38, Joost Kremers wrote:
On Wed, Nov 30 2016, Andreas Röhler wrote:Hi,see code below. With numerical argument "1", first pattern is matched as expected.However without arg the minus is matched - the second pattern, not the default "_" at last.Any explanation? (defun foo (arg) (interactive "P") (pcase arg (1 (message "%s" "ARG was `1'")) (- (message "%s" "ARG was minus-sign")) (_ (message "%s" "ARG not minus-sign"))))Probably because - is a symbol and hence a variable. It works if you quote it:(defun foo (arg) (interactive "P") (pcase arg (1 (message "%s" "ARG was `1'")) ('- (message "%s" "ARG was minus-sign")) (_ (message "%s" "ARG not minus-sign"))))
Thanks, that helps. Seems it relates to the following in docstring: SYMBOL matches anything and binds it to SYMBOL. 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.
[Prev in Thread] | Current Thread | [Next in Thread] |