unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19670: 24.4; pcase-let bug?
@ 2015-01-24  2:42 Leo Liu
  2015-01-24  5:07 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Leo Liu @ 2015-01-24  2:42 UTC (permalink / raw)
  To: 19670


Eval the following two expressions:

1.
(pcase-let ((`(,x) '(1 2 3)))
  (list x))

2.
(pcase '(1 2 3)
  (`(,x) (list x)))

1 produces (1) and 2 nil. Bug?

Leo





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#19670: 24.4; pcase-let bug?
  2015-01-24  2:42 bug#19670: 24.4; pcase-let bug? Leo Liu
@ 2015-01-24  5:07 ` Stefan Monnier
  2015-01-26 14:27   ` Leo Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2015-01-24  5:07 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19670

> 1 produces (1) and 2 nil. Bug?

Feature: the `pcase' form can have several branches (and defaults to
nil if no branch matches), whereas the `pcase-let' form doesn't have the
luxury of a "default case if it doesn't match", so we have to choose
between "signal an error if it doesn't match" or "pretend it matched".
I opted for the second choice.


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#19670: 24.4; pcase-let bug?
  2015-01-24  5:07 ` Stefan Monnier
@ 2015-01-26 14:27   ` Leo Liu
  2015-01-26 22:59     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Leo Liu @ 2015-01-26 14:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 19670

On 2015-01-24 13:07 +0800, Stefan Monnier wrote:
> Feature: the `pcase' form can have several branches (and defaults to
> nil if no branch matches), whereas the `pcase-let' form doesn't have the
> luxury of a "default case if it doesn't match", so we have to choose
> between "signal an error if it doesn't match" or "pretend it matched".
> I opted for the second choice.

I still find this inconsistent. Another similar-looking example:

(pcase 'whatever
  ((let `(,x) '(1 2 3)) (list x))) ;; => nil

It seems to make more sense for pcase-let to signal an error or bind X
to nil. WDYT?

Leo





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#19670: 24.4; pcase-let bug?
  2015-01-26 14:27   ` Leo Liu
@ 2015-01-26 22:59     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2015-01-26 22:59 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19670

> It seems to make more sense for pcase-let to signal an error or bind X
> to nil. WDYT?

Signaling an error would be fine.  But it significantly increases the
macro-expanded code size (i.e. it's a lot less efficient).
Defaulting to binding all vars to nil in case of match failure seems
like an even more surprising behavior than what we have now.

The current pcase-let (and pcase-dolist) is meant as a "destructuring"
operation: it doesn't *check* anything, it just accesses subelements of
a structure.


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-01-26 22:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-24  2:42 bug#19670: 24.4; pcase-let bug? Leo Liu
2015-01-24  5:07 ` Stefan Monnier
2015-01-26 14:27   ` Leo Liu
2015-01-26 22:59     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).