GNU bug report logs - #16567
24.3.50; pcase should signal an error if no case matches

Previous Next

Package: emacs;

Reported by: Helmut Eller <eller.helmut <at> gmail.com>

Date: Mon, 27 Jan 2014 09:24:01 UTC

Severity: wishlist

Found in version 24.3.50

Fixed in version 25.1

Done: Leo Liu <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Leo Liu <sdl.web <at> gmail.com>
Subject: bug#16567: 24.3.50; pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 13:26:14 -0400
>> I'm open to other suggestions, and `pcasex' is not unacceptable, so
>> I think we're closing in.
> pcase* looks less exotic that pcasex; though it's harder to type.
> BTW, I find it surprising that this doesn't signal an error:
> (pcase-let ((`(1 ,x) '("foo")))
>  x)

Indeed, the semantics of pcase-let is a bit subtle: rather than use the
pattern as a filter to decide whether to match or not, it just assumes
that the match is a success and accesses the data accordingly.

So the above expands to something morally equivalent to

   (let ((x (cadr '("foo")))) x)

> But I suspect that "it's not an option" to change pcase-let.

I don't think backward compatibility is as much of an issue for
pcase-let, but the motivation for this semantics was efficiency, and
this is still as valid as ever, AFAIK.

For single-branch pcase-let, the alternative

   (pcase-exhaustive '("foo")
     (`(1 ,x) x))

is a good replacement to get the semantics you expect.  But admittedly,
for if you have several bindings in your pcase-let, the equivalent
pcase-exhaustive can become inconvenient.


        Stefan




This bug report was last modified 10 years and 290 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.