unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
@ 2024-06-12  8:40 Mekeor Melire
  2024-06-14  8:42 ` Philip Kaludercic
  0 siblings, 1 reply; 4+ messages in thread
From: Mekeor Melire @ 2024-06-12  8:40 UTC (permalink / raw)
  To: 71503

I was expecting these two expressions to evaluate to the same value.
First, we call `pcase' on a value with a pattern involving `and' and
`guard':

    (pcase "value"
      ((and v (guard (string= "not-value" v))) v))
    ;; => nil

Second, let's use the same value and pattern, but this time using
`pcase-lambda':

    (funcall
      (pcase-lambda
        ((and v (guard (string= "not-value" v)))) v)
      "value")
    ;; => "value"

Am I missing something or is this a bug?

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.41, cairo version 1.16.0).





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

* bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
  2024-06-12  8:40 bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected Mekeor Melire
@ 2024-06-14  8:42 ` Philip Kaludercic
  2024-06-14 16:08   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-06-22  8:37   ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Philip Kaludercic @ 2024-06-14  8:42 UTC (permalink / raw)
  To: Mekeor Melire; +Cc: 71503

Mekeor Melire <mekeor@posteo.de> writes:

> I was expecting these two expressions to evaluate to the same value.
> First, we call `pcase' on a value with a pattern involving `and' and
> `guard':
>
>     (pcase "value"
>       ((and v (guard (string= "not-value" v))) v))
>     ;; => nil
>
> Second, let's use the same value and pattern, but this time using
> `pcase-lambda':
>
>     (funcall
>       (pcase-lambda
>         ((and v (guard (string= "not-value" v)))) v)
>       "value")
>     ;; => "value"
>
> Am I missing something or is this a bug?

The difference is that pcase-lambda doesn't do case-distinction, but
just pattern matching/destruncting.  So if the pattern-matching fails,
then the variable is just not bound, instead of the entire expression
falling back to returning no value/nil.  I am guessing you wanted to
have something like Scheme's `case-lambda'[0]?  Or we could clarify this
point in the docstring.

> In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
> 3.24.41, cairo version 1.16.0).

[0] https://index.scheme.org/filterset/r7rs_small/%28scheme%2520case-lambda%29/case-lambda

-- 
	Philip Kaludercic on peregrine





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

* bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
  2024-06-14  8:42 ` Philip Kaludercic
@ 2024-06-14 16:08   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-06-22  8:37   ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-06-14 16:08 UTC (permalink / raw)
  To: Philip Kaludercic, Mekeor Melire; +Cc: 71503@debbugs.gnu.org

> The difference is that pcase-lambda
> doesn't do case-distinction, but
> just pattern matching/destruncting.

Unless I'm mistaken, this confusion has
surfaced several times now...

Is it really a good idea to call this
"pcase-" <anything>, if it has nothing to
do with case distinction, i.e., control
flow?

Why not a name that suggests destructuring
or pattern-matching, and binding?  Common
Lisp at least calls its (weaker) construct
`destructuring-bind' - pretty clear.








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

* bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected
  2024-06-14  8:42 ` Philip Kaludercic
  2024-06-14 16:08   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-06-22  8:37   ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-06-22  8:37 UTC (permalink / raw)
  To: Philip Kaludercic, Stefan Monnier; +Cc: mekeor, 71503

> Cc: 71503@debbugs.gnu.org
> From: Philip Kaludercic <philipk@posteo.net>
> Date: Fri, 14 Jun 2024 08:42:25 +0000
> 
> Mekeor Melire <mekeor@posteo.de> writes:
> 
> > I was expecting these two expressions to evaluate to the same value.
> > First, we call `pcase' on a value with a pattern involving `and' and
> > `guard':
> >
> >     (pcase "value"
> >       ((and v (guard (string= "not-value" v))) v))
> >     ;; => nil
> >
> > Second, let's use the same value and pattern, but this time using
> > `pcase-lambda':
> >
> >     (funcall
> >       (pcase-lambda
> >         ((and v (guard (string= "not-value" v)))) v)
> >       "value")
> >     ;; => "value"
> >
> > Am I missing something or is this a bug?
> 
> The difference is that pcase-lambda doesn't do case-distinction, but
> just pattern matching/destruncting.  So if the pattern-matching fails,
> then the variable is just not bound, instead of the entire expression
> falling back to returning no value/nil.  I am guessing you wanted to
> have something like Scheme's `case-lambda'[0]?  Or we could clarify this
> point in the docstring.

Would you mind suggesting a clarification for the doc string (and the
ELisp manual as well)?

Thanks.





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

end of thread, other threads:[~2024-06-22  8:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12  8:40 bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected Mekeor Melire
2024-06-14  8:42 ` Philip Kaludercic
2024-06-14 16:08   ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-22  8:37   ` Eli Zaretskii

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