[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pcase and minus-sign

From: Joost Kremers
Subject: Re: pcase and minus-sign
Date: Wed, 30 Nov 2016 14:56:18 +0100
User-agent: mu4e 0.9.17; emacs

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.


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" _))

Joost Kremers
Life has its moments

reply via email to

[Prev in Thread] Current Thread [Next in Thread]