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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16567 in the body.
You can then email your comments to 16567 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 27 Jan 2014 09:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Helmut Eller <eller.helmut <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 27 Jan 2014 09:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; pcase should signal an error if no case matches
Date: Mon, 27 Jan 2014 10:22:06 +0100
pcase returns nil for this example:

 (pcase 3
   (1 1)
   (2 2))

it would be more useful if it would signal an error instead.  Manually
adding a "catch-all case" and inventing some error message is tedious
and it's also easy to forget.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 27 Jan 2014 10:19:01 GMT) Full text and rfc822 format available.

Message #8 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Daimrod <daimrod <at> gmail.com>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Mon, 27 Jan 2014 11:27:26 +0100
Helmut Eller <eller.helmut <at> gmail.com> writes:

> pcase returns nil for this example:
>
>  (pcase 3
>    (1 1)
>    (2 2))
>
> it would be more useful if it would signal an error instead.  Manually
> adding a "catch-all case" and inventing some error message is tedious
> and it's also easy to forget.

Wouldn't a `epcase' (as in `cl-ecase') be more appropriate for this
use-case?

-- 
Daimrod/Greg




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 27 Jan 2014 11:57:02 GMT) Full text and rfc822 format available.

Message #11 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Daimrod <daimrod <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Mon, 27 Jan 2014 12:56:06 +0100
On Mon, Jan 27 2014, Daimrod wrote:

> Helmut Eller <eller.helmut <at> gmail.com> writes:
>
>> pcase returns nil for this example:
>>
>>  (pcase 3
>>    (1 1)
>>    (2 2))
>>
>> it would be more useful if it would signal an error instead.  Manually
>> adding a "catch-all case" and inventing some error message is tedious
>> and it's also easy to forget.
>
> Wouldn't a `epcase' (as in `cl-ecase') be more appropriate for this
> use-case?

My gut feeling is that in 80% of all situations ECASE is more or just as
appropriate as CASE.  Or put differently it's very uncommon that CASE is
preferable to ECASE.  Therefore I think pcase should singal an error by
default.

The nice thing about a epcase would be the symmetry/analogy to
ECASE/ETYPECASE.  But that seems like a minor advantage.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 27 Jan 2014 12:15:01 GMT) Full text and rfc822 format available.

Message #14 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Daimrod <daimrod <at> gmail.com>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Mon, 27 Jan 2014 13:23:30 +0100
Helmut Eller <eller.helmut <at> gmail.com> writes:

> On Mon, Jan 27 2014, Daimrod wrote:
>
>> Helmut Eller <eller.helmut <at> gmail.com> writes:
>>
>>> pcase returns nil for this example:
>>>
>>>  (pcase 3
>>>    (1 1)
>>>    (2 2))
>>>
>>> it would be more useful if it would signal an error instead.  Manually
>>> adding a "catch-all case" and inventing some error message is tedious
>>> and it's also easy to forget.
>>
>> Wouldn't a `epcase' (as in `cl-ecase') be more appropriate for this
>> use-case?
>
> My gut feeling is that in 80% of all situations ECASE is more or just as
> appropriate as CASE.  Or put differently it's very uncommon that CASE is
> preferable to ECASE.  Therefore I think pcase should singal an error by
> default.
>
> The nice thing about a epcase would be the symmetry/analogy to
> ECASE/ETYPECASE.  But that seems like a minor advantage.

It also has the advantage of not breaking existing code that relies on
its current behavior, though I agree that most of the time I use ECASE
instead of CASE.

> Helmut

-- 
Daimrod/Greg




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 08 Sep 2014 18:28:02 GMT) Full text and rfc822 format available.

Message #17 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Tue, 09 Sep 2014 02:27:08 +0800
On 2014-01-27 10:22 +0100, Helmut Eller wrote:
> pcase returns nil for this example:
>
>  (pcase 3
>    (1 1)
>    (2 2))
>
> it would be more useful if it would signal an error instead.  Manually
> adding a "catch-all case" and inventing some error message is tedious
> and it's also easy to forget.

Hi Stefan,

I also find myself wanting something as Helmut suggested more and more.
Any comments in the following patch? Thanks. Leo

=== modified file 'lisp/emacs-lisp/pcase.el'
--- lisp/emacs-lisp/pcase.el	2014-09-06 00:59:00 +0000
+++ lisp/emacs-lisp/pcase.el	2014-09-08 18:15:37 +0000
@@ -68,6 +68,8 @@
 
 (defconst pcase--dontcare-upats '(t _ pcase--dontcare))
 
+(defvar pcase--dontwarn-upats '(pcase--dontcare))
+
 (def-edebug-spec
   pcase-UPAT
   (&or symbolp
@@ -148,6 +150,14 @@
         ;; (puthash (car cases) `(,exp ,cases ,@expansion) pcase--memoize-2)
         expansion))))
 
+;;;###autoload
+(defmacro xcase (exp &rest cases)
+  (declare (indent 1) (debug pcase))
+  (let* ((x (make-symbol "x"))
+         (pcase--dontwarn-upats (cons x pcase--dontwarn-upats)))
+    (pcase--expand
+     exp (append cases `((,x (error "No clause matching `%S'" ,x)))))))
+
 (defun pcase--let* (bindings body)
   (cond
    ((null bindings) (macroexp-progn body))
@@ -280,7 +290,8 @@
                              vars))))
                      cases))))
       (dolist (case cases)
-        (unless (or (memq case used-cases) (eq (car case) 'pcase--dontcare))
+        (unless (or (memq case used-cases)
+                    (memq (car case) pcase--dontwarn-upats))
           (message "Redundant pcase pattern: %S" (car case))))
       (macroexp-let* defs main))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 08 Sep 2014 19:20:02 GMT) Full text and rfc822 format available.

Message #20 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Mon, 08 Sep 2014 15:19:06 -0400
> pcase returns nil for this example:
>  (pcase 3
>    (1 1)
>    (2 2))
> it would be more useful if it would signal an error instead.  Manually
> adding a "catch-all case" and inventing some error message is tedious
> and it's also easy to forget.

The "nil default" is also very handy at times and pcase has been in use
for long enough that we can't really change this easily.

But we could add a new pcase-exhaustive macro that does that.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Mon, 08 Sep 2014 20:59:01 GMT) Full text and rfc822 format available.

Message #23 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Mon, 08 Sep 2014 22:58:05 +0200
On Mon, Sep 08 2014, Stefan Monnier wrote:

>> pcase returns nil for this example:
>>  (pcase 3
>>    (1 1)
>>    (2 2))
>> it would be more useful if it would signal an error instead.  Manually
>> adding a "catch-all case" and inventing some error message is tedious
>> and it's also easy to forget.
>
> The "nil default" is also very handy at times and pcase has been in use
> for long enough that we can't really change this easily.

What could happen if you would change it?  Mostly some "no clause
matching" errors.  Arguably better than the current situation where
poeple forget the unintuitive default and receive no error message.

> But we could add a new pcase-exhaustive macro that does that.

Nobody wants to use such a long name.  The "nil default" would make more
sense in a pcase-if or pif macro.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Tue, 09 Sep 2014 00:42:01 GMT) Full text and rfc822 format available.

Message #26 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Mon, 08 Sep 2014 20:41:01 -0400
> What could happen if you would change it?

Obviously: errors signaled instead of returning the expected nil.
Returning nil by default is "the norm" in Elisp (think of missing `else'
branches in `if', or missing default case in `cond' or even missing
default case in `cl-case'), so it's to be expected that pcase users
would rely on this default behavior as well, even if it strikes you as
utter nonsense.

> The "nil default" would make more sense in a pcase-if or pif macro.

Changing the default of `pcase' is not an option at this point.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 00:03:01 GMT) Full text and rfc822 format available.

Message #29 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 08:02:35 +0800
On 2014-09-08 20:41 -0400, Stefan Monnier wrote:
> Changing the default of `pcase' is not an option at this point.

What's the way forward?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 02:27:01 GMT) Full text and rfc822 format available.

Message #32 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Tue, 09 Sep 2014 22:26:34 -0400
>> Changing the default of `pcase' is not an option at this point.
> What's the way forward?

I suggested `pcase-exhaustive'.
You suggested `xcase', which I don't like for namespace reasons.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 02:53:02 GMT) Full text and rfc822 format available.

Message #35 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 10:52:18 +0800
On 2014-09-09 22:26 -0400, Stefan Monnier wrote:
> I suggested `pcase-exhaustive'.
> You suggested `xcase', which I don't like for namespace reasons.

Would `pcasex' be acceptable? I used xcase because I cannot come up with
a good enough short name, and a long name for such a fundamental macro
can be annoying.

Thanks,
Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 05:33:02 GMT) Full text and rfc822 format available.

Message #38 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Josh <josh <at> foxtail.org>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Tue, 9 Sep 2014 22:32:19 -0700
[Message part 1 (text/plain, inline)]
On Tue, Sep 9, 2014 at 7:52 PM, Leo Liu <sdl.web <at> gmail.com> wrote:

> On 2014-09-09 22:26 -0400, Stefan Monnier wrote:
> > I suggested `pcase-exhaustive'.
> > You suggested `xcase', which I don't like for namespace reasons.
>
> Would `pcasex' be acceptable? I used xcase because I cannot come up with
> a good enough short name, and a long name for such a fundamental macro
> can be annoying.
>

How is the special case of erroring upon failure to match a "fundamental
macro"?
If this needs to exist then Stefan's suggestion of `pcase-exhaustive' or
some other
descriptive name seems like the way to go, but just appending "x" for the
sake of
brevity seems like a bad idea.  Clarity is more important.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 06:19:01 GMT) Full text and rfc822 format available.

Message #41 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Josh <josh <at> foxtail.org>
Cc: 16567 <at> debbugs.gnu.org, Leo Liu <sdl.web <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 08:18:24 +0200
On Tue, Sep 09 2014, Josh wrote:

> How is the special case of erroring upon failure to match a "fundamental
> macro"?

It's not a special case.  It's by far the most common case for me.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 13:18:02 GMT) Full text and rfc822 format available.

Message #44 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 09:17:31 -0400
> Would `pcasex' be acceptable?

It's kind of ugly, and I'm not sure what the "x" stands for.

> I used xcase because I cannot come up with a good enough short name,
> and a long name for such a fundamental macro can be annoying.

`pcase-e TAB' should expand to `pcase-exhaustive', so the length is not
that troublesome, unless you're concerned about line-length and
indentation (in which case the length of `pcase-exhaustive' may indeed
occasionally force you to use an extra line).

I'm open to other suggestions, and `pcasex' is not unacceptable, so
I think we're closing in.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 14:29:01 GMT) Full text and rfc822 format available.

Message #47 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org, Leo Liu <sdl.web <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 16:28:40 +0200
On Wed, Sep 10 2014, Stefan Monnier wrote:

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

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

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 14:34:02 GMT) Full text and rfc822 format available.

Message #50 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 22:33:11 +0800
On 2014-09-10 09:17 -0400, Stefan Monnier wrote:
> unless you're concerned about line-length and
> indentation (in which case the length of `pcase-exhaustive' may indeed
> occasionally force you to use an extra line).
>
> I'm open to other suggestions, and `pcasex' is not unacceptable, so
> I think we're closing in.

pcasex = PCASe + EXhaustive

Yes, line length and indentation is my main concern. 

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 16:55:02 GMT) Full text and rfc822 format available.

Message #53 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>,
 Leo Liu <sdl.web <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 12:54:41 -0400
Stefan Monnier wrote:

> I'm open to other suggestions, and `pcasex' is not unacceptable, so
> I think we're closing in.

And would you be prepared to add the
entirely-equivalent-but-somehow-we-managed-fine-without-them-all-this-time
condx and cl-casex?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 17:27:01 GMT) Full text and rfc822 format available.

Message #56 received at 16567 <at> debbugs.gnu.org (full text, mbox):

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: Re: 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 17:40:01 GMT) Full text and rfc822 format available.

Message #59 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org, eller.helmut <at> gmail.com, sdl.web <at> gmail.com
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 13:39:12 -0400
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

pcasex means sex on a very small scale
;-)

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Wed, 10 Sep 2014 17:55:02 GMT) Full text and rfc822 format available.

Message #62 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>,
 Leo Liu <sdl.web <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Wed, 10 Sep 2014 13:54:18 -0400
>> I'm open to other suggestions, and `pcasex' is not unacceptable, so
>> I think we're closing in.
> And would you be prepared to add the
> entirely-equivalent-but-somehow-we-managed-fine-without-them-all-this-time
> condx and cl-casex?

We already have `cl-ecase'.  As for `condx', no I'd rather not ;-)


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Fri, 12 Sep 2014 02:36:02 GMT) Full text and rfc822 format available.

Message #65 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 16567 <at> debbugs.gnu.org, Glenn Morris <rgm <at> gnu.org>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Fri, 12 Sep 2014 10:35:29 +0800
Stefan,

Which name would you prefer, `epcase' or 'pcasex'? Do you see any
problems with the following patch (assume `pcasex' for now)?

Thanks, Leo

=== modified file 'lisp/emacs-lisp/lisp-mode.el'
--- lisp/emacs-lisp/lisp-mode.el	2014-06-19 14:03:45 +0000
+++ lisp/emacs-lisp/lisp-mode.el	2014-09-12 02:28:44 +0000
@@ -197,7 +197,7 @@
               (el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local"
                           "defface"))
               (el-tdefs '("defgroup" "deftheme"))
-              (el-kw '("while-no-input" "letrec" "pcase" "pcase-let"
+              (el-kw '("while-no-input" "letrec" "pcase" "pcasex" "pcase-let"
                        "pcase-let*" "save-restriction" "save-excursion"
                        "save-selected-window"
                        ;; "eval-after-load" "eval-next-after-load"

=== modified file 'lisp/emacs-lisp/pcase.el'
--- lisp/emacs-lisp/pcase.el	2014-09-06 00:59:00 +0000
+++ lisp/emacs-lisp/pcase.el	2014-09-10 10:44:59 +0000
@@ -68,6 +68,8 @@
 
 (defconst pcase--dontcare-upats '(t _ pcase--dontcare))
 
+(defvar pcase--dontwarn-upats '(pcase--dontcare))
+
 (def-edebug-spec
   pcase-UPAT
   (&or symbolp
@@ -148,6 +150,15 @@
         ;; (puthash (car cases) `(,exp ,cases ,@expansion) pcase--memoize-2)
         expansion))))
 
+;;;###autoload
+(defmacro pcasex (exp &rest cases)
+  "The exhausitive version of `pcase' (which see)."
+  (declare (indent 1) (debug pcase))
+  (let* ((x (make-symbol "x"))
+         (pcase--dontwarn-upats (cons x pcase--dontwarn-upats)))
+    (pcase--expand
+     exp (append cases `((,x (error "No clause matching `%S'" ,x)))))))
+
 (defun pcase--let* (bindings body)
   (cond
    ((null bindings) (macroexp-progn body))
@@ -280,7 +291,8 @@
                              vars))))
                      cases))))
       (dolist (case cases)
-        (unless (or (memq case used-cases) (eq (car case) 'pcase--dontcare))
+        (unless (or (memq case used-cases)
+                    (memq (car case) pcase--dontwarn-upats))
           (message "Redundant pcase pattern: %S" (car case))))
       (macroexp-let* defs main))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Fri, 12 Sep 2014 17:16:01 GMT) Full text and rfc822 format available.

Message #68 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Glenn Morris <rgm <at> gnu.org>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Fri, 12 Sep 2014 13:15:08 -0400
> Which name would you prefer, `epcase' or 'pcasex'? Do you see any
> problems with the following patch (assume `pcasex' for now)?

For now, pcase-exhaustive is still a better choice.
A quick grep shows that most first args to pcase are rather short, so
the line-length argument is not very compelling.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Sat, 13 Sep 2014 00:30:03 GMT) Full text and rfc822 format available.

Message #71 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Sat, 13 Sep 2014 08:29:38 +0800
On 2014-09-12 13:15 -0400, Stefan Monnier wrote:
> For now, pcase-exhaustive is still a better choice.
> A quick grep shows that most first args to pcase are rather short, so
> the line-length argument is not very compelling.

OK, let's go with `pcase-exhaustive' for now. Any objection if we also
make an short alias to it for the convenience of people that know they
want the exhaustive version most of the time?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Sat, 13 Sep 2014 03:11:02 GMT) Full text and rfc822 format available.

Message #74 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Fri, 12 Sep 2014 23:10:48 -0400
>> For now, pcase-exhaustive is still a better choice.
>> A quick grep shows that most first args to pcase are rather short, so
>> the line-length argument is not very compelling.
> OK, let's go with `pcase-exhaustive' for now. Any objection if we also
> make an short alias to it for the convenience of people that know they
> want the exhaustive version most of the time?

No, I'd rather wait to see if it's really used that often.  If it turns
out to be popular, we can then add a shorter version.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Sat, 13 Sep 2014 04:58:02 GMT) Full text and rfc822 format available.

Message #77 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Sat, 13 Sep 2014 12:57:16 +0800
On 2014-09-12 23:10 -0400, Stefan Monnier wrote:
> No, I'd rather wait to see if it's really used that often.  If it turns
> out to be popular, we can then add a shorter version.
>
>
>         Stefan

Should I install the patch (with the name change of course)?

Leo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16567; Package emacs. (Sat, 13 Sep 2014 15:02:01 GMT) Full text and rfc822 format available.

Message #80 received at 16567 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: 16567 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Sat, 13 Sep 2014 11:01:16 -0400
>> No, I'd rather wait to see if it's really used that often.  If it turns
>> out to be popular, we can then add a shorter version.
> Should I install the patch (with the name change of course)?

Yes, go ahead,


        Stefan




Reply sent to Leo Liu <sdl.web <at> gmail.com>:
You have taken responsibility. (Sat, 13 Sep 2014 17:27:02 GMT) Full text and rfc822 format available.

Notification sent to Helmut Eller <eller.helmut <at> gmail.com>:
bug acknowledged by developer. (Sat, 13 Sep 2014 17:27:03 GMT) Full text and rfc822 format available.

Message #85 received at 16567-done <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 16567-done <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#16567: 24.3.50;
 pcase should signal an error if no case matches
Date: Sun, 14 Sep 2014 01:25:52 +0800
Version: 24.5

On 2014-09-13 11:01 -0400, Stefan Monnier wrote:
> Yes, go ahead,

Done.

Leo




bug Marked as fixed in versions 25.1. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sat, 04 Oct 2014 16:33:02 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 24.5. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sat, 04 Oct 2014 16:33:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 02 Nov 2014 12:24:08 GMT) Full text and rfc822 format available.

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

Previous Next


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