Subject: Re: bug#16567: 24.3.50; pcase should signal an error if no case matches

From: Stefan Monnier <[email-masked]>
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