help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: pcase and minus-sign


From: Stefan Monnier
Subject: Re: pcase and minus-sign
Date: Thu, 01 Dec 2016 21:30:48 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

>>> 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 same thing that makes it different in "normal" Lisp code. 1 is read as
>> an integer, not as a symbol.

> Thanks all again!

BTW, the driving idea behind the shape of pcase patterns is more or less
that a pattern PAT matches the value V if an expression PAT could
evaluate to the value V.

So for the pattern 1, it will match any value that is equal to the
evaluation of the expression 1, i.e. it only matches the value 1.

For pattern 'a, it will match any value that is equal to the evaluation
of the expression 'a, which means it the value has to be the symbol `a`.

Whereas for pattern a, it will match any value that can be equal to the
evaluation of the expression a, which means any value (under the
assumption that the variable `a` has the appropriate value).


        Stefan




reply via email to

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