From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#71503: 30.0.50; pcase-lambda (with "and" and "guard") does not work as expected Date: Sat, 20 Jul 2024 10:29:55 +0000 Message-ID: <87ikx0mk4c.fsf@posteo.net> References: <87r0d2lfjd.fsf@posteo.de> <87h6dvud8u.fsf@posteo.net> <86tthlidap.fsf@gnu.org> <86frsn55t3.fsf@gnu.org> <865xt0e6wc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37195"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mekeor@posteo.de, monnier@iro.umontreal.ca, 71503@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 20 12:31:24 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sV7N5-0009Qh-Jd for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Jul 2024 12:31:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sV7Mo-000732-7D; Sat, 20 Jul 2024 06:31:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sV7Mk-00072H-L4 for bug-gnu-emacs@gnu.org; Sat, 20 Jul 2024 06:31:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sV7Mk-0002R6-Cs for bug-gnu-emacs@gnu.org; Sat, 20 Jul 2024 06:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sV7Mk-0003tN-GF for bug-gnu-emacs@gnu.org; Sat, 20 Jul 2024 06:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Jul 2024 10:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71503 X-GNU-PR-Package: emacs Original-Received: via spool by 71503-submit@debbugs.gnu.org id=B71503.172147140914823 (code B ref 71503); Sat, 20 Jul 2024 10:31:02 +0000 Original-Received: (at 71503) by debbugs.gnu.org; 20 Jul 2024 10:30:09 +0000 Original-Received: from localhost ([127.0.0.1]:51868 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sV7Ls-0003qz-Kg for submit@debbugs.gnu.org; Sat, 20 Jul 2024 06:30:09 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:36751) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sV7Lq-0003pv-00 for 71503@debbugs.gnu.org; Sat, 20 Jul 2024 06:30:07 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 64177240028 for <71503@debbugs.gnu.org>; Sat, 20 Jul 2024 12:29:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1721471398; bh=bXOf150drr+G6o87o04NWuMeD7enAc9XE4FO6ByaCCM=; h=From:To:Cc:Subject:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=I0KANMapo+d5LiItKPPKdV0Fl1N4pCbUkgGPCpea1/qcvpoQbh/9TIKcH/SVkmPIC bhl5EGST3iiP86vPlGWCc4whokBRlZBk2UeEIbOnGUDteo+SsFqyoYSi+yuGTobVZM 4XxtLWMPhezYsvHcZnMULf4pXWqnuSTqN/sk8nZInhzlZg0eUIdcofgbyEGmwVAEBC P61iC9C0yNnwQW6vP9I6e6Byeb/3wo0CvhZ/RKJgi5dCuOLWQOFAA+B4IIb1HBqI6M v7lKQzirNjsCu82tvAb7ChMSBFvxKQQxzQGGkUYnUPmNl0eG4qbFg+HDiHyjoxGhdY BD9jKRJAJBeLw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4WR2q909CWz6trs; Sat, 20 Jul 2024 12:29:55 +0200 (CEST) In-Reply-To: <865xt0e6wc.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 20 Jul 2024 12:42:43 +0300") OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:289037 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > Ping! Ping! > >> Cc: mekeor@posteo.de, monnier@iro.umontreal.ca, 71503@debbugs.gnu.org >> Date: Sat, 06 Jul 2024 10:38:00 +0300 >> From: Eli Zaretskii >> >> Ping! >> >> > Cc: mekeor@posteo.de, 71503@debbugs.gnu.org >> > Date: Sat, 22 Jun 2024 11:37:02 +0300 >> > From: Eli Zaretskii >> > >> > > Cc: 71503@debbugs.gnu.org >> > > From: Philip Kaludercic >> > > Date: Fri, 14 Jun 2024 08:42:25 +0000 >> > > >> > > Mekeor Melire 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)? Sorry, I didn't realise you were pining me. I was thinking of something like --=-=-= Content-Type: text/plain Content-Disposition: inline diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index 5a7f3995311..f546ba34c7c 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -241,9 +241,10 @@ pcase-exhaustive ;;;###autoload (defmacro pcase-lambda (lambda-list &rest body) "Like `lambda' but allow each argument to be a pattern. -I.e. accepts the usual &optional and &rest keywords, but every -formal argument can be any pattern accepted by `pcase' (a mere -variable name being but a special case of it)." +I.e. accepts the usual &optional and &rest keywords, but every formal +argument can be any pattern accepted by `pcase' (a mere variable name +being but a special case of it). Keep in mind that BODY is always +evaluated, regardless of whether the argument-patterns match or not." (declare (doc-string 2) (indent defun) (debug (&define (&rest pcase-PAT) lambda-doc def-body))) (let* ((bindings ()) --=-=-= Content-Type: text/plain but now I notice that `pcase-let*' documents that all expressions should match, Each EXP should match its respective PATTERN (i.e. be of structure compatible to PATTERN); a mismatch may signal an error or may go undetected, binding variables to arbitrary values, such as nil. Since `pcase-lambda' inherits these semantics we would have to propagate this promise -- or be more specific about what happens, e.g. binding values to nil. >> > Thanks. -- Philip Kaludercic on peregrine --=-=-=--