From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#59887: pcase vs. pcase-let: Underscore in backquote-style patterns Date: Fri, 09 Dec 2022 03:57:31 +0100 Message-ID: <87edt9nv1g.fsf@web.de> References: <87sfhrqgxw.fsf@airmail.cc> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29884"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 59887@debbugs.gnu.org To: hokomo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 09 03:58:21 2022 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 1p3Tad-0007Wi-RB for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 09 Dec 2022 03:58:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3TaO-0005rV-8O; Thu, 08 Dec 2022 21:58:04 -0500 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 1p3TaM-0005r7-IN for bug-gnu-emacs@gnu.org; Thu, 08 Dec 2022 21:58:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p3TaM-0005TA-8d for bug-gnu-emacs@gnu.org; Thu, 08 Dec 2022 21:58:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p3TaM-0000lT-26 for bug-gnu-emacs@gnu.org; Thu, 08 Dec 2022 21:58:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Dec 2022 02:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59887 X-GNU-PR-Package: emacs Original-Received: via spool by 59887-submit@debbugs.gnu.org id=B59887.16705546642932 (code B ref 59887); Fri, 09 Dec 2022 02:58:02 +0000 Original-Received: (at 59887) by debbugs.gnu.org; 9 Dec 2022 02:57:44 +0000 Original-Received: from localhost ([127.0.0.1]:60695 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p3Ta4-0000lE-E7 for submit@debbugs.gnu.org; Thu, 08 Dec 2022 21:57:44 -0500 Original-Received: from mout.web.de ([212.227.15.3]:51435) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p3TZy-0000l5-VC for 59887@debbugs.gnu.org; Thu, 08 Dec 2022 21:57:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1670554652; bh=AlFW0mRP5TuqAwZRHVSYdXzRYkNMat2cV+eYUo+tYxo=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=EXQHivJI017f2s9RcNH/MVshkl8V9Z9vPEb8BBgJPQ9P3v78qtqCX7Kw3hDj6xQ/A et5O930s+MFTH9Cx3d2DDlpM7a+39GxBpAqj5s+uMwZ2nHe7hRyq3gSssGBo9OVYnU UdF+NYuKE/Bl02pJmnQXTHQly1EWbQBDeNeX+SlXj2OnatqGYOvWBlQpyJ590js/df GFKdMIUiw/wt1Qr9+rEDIYXxjdrEF/sDjmomrItghskW3GqguVWEhK5I1CCwOBo2fq seA3FY/NI1byYFs94AelZh+pkItlFxGLY+oyoEtoZ3nHkNRYcxm8bfmCF9G05nLAhO HYHEbyXfP0/mA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([92.76.229.140]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MlsON-1ocdQ03zW7-00iyGL; Fri, 09 Dec 2022 03:57:32 +0100 In-Reply-To: <87sfhrqgxw.fsf@airmail.cc> (hokomo@airmail.cc's message of "Wed, 07 Dec 2022 17:28:57 +0100") X-Provags-ID: V03:K1:PHHCEdeey8qSGKsIwuOKGP5V0MD+g3GFa20Fen2aO4MWVNv6gXI y14YmHNXSayPILyZu/eU6H3n3E164U6UiBOvmY0LjZnwmArvZx/yumDrO8rBG5YHg3hRYzZ JDoQhyGroNSK0uU4xsH6wqoLR2q+FXwkqsV9FgcU4HMqEYGpNp96q6WSHllXpSEkJJ6pi6G BRgYBCGCQFhJhCJ9LlwDg== UI-OutboundReport: notjunk:1;M01:P0:bb1KcLmidAE=;tV5JPZ6a+flxA6eEyngHB55tV72 tvgZyzhaFtUP/ndBKlnNzsr6t4zHQb2+PXYAeSwvEEoofAv7LWWdnYXPCcGDrmV84ukfpmBQ4 YEhiiMNbG/qEIwjLyzwtinUSX4gr8L51l9gF9gwox09s8bE9IIcNfs8163uEJeSSC7GlIiPMp rL0NSpJe/D+kMJ5dZyjnKFVYb+LQt6AB8xPzZBO87dIwTjzwNT67p7093RMv+ynhgJl3lrTdY kSARirgqPDJtJQeGoyjTkc9Xc2pMc9jHX6pVCJjX8JRm4SCpvEBEyS3KdeeDb2I9WgLmtFWTp zfCxNQcuNB8ZcHQ58NbK3NLC71htXIvdtHRaBwslaVd4rn0eH6orxCwODzhOt2fcVZpIAZ3n/ CQ/jONCqDl7dwLX6aE+Jdi0TiQPCg6EfBT1/nPUxzkjuypRAG0r/xSrxQacAPRodE3Y7drtdE xzNhunGgR2lcdwsCDlf4K4h60NxykofpUNF1IgTelGfvLFXDvQ1GaRVYeylCzXOvtyFMP8K9J pu2g5R41opSoGI2oaxqxrNuQZ6OPvLektoKICPQnm6OZlNYd3ut/+/p/LrAXMlpWmqup0VUgi jTCoTcZXjgmzfPlXttTsca1Ll6W4z6+OoB5Fb4P9tIxvucEEKmbPVyiVnQnQLwotNGYbNjb46 b+fdtwuHwhk2yACFpBSu5n4W79OKs4Fuer1RnKvyFIBSUyZfVVX1YGe3ZDmf0cTAyfRqwlLy+ UtBkdY1/fr+gME/lCTPROQSsTsD0EhsE6t9voBdi5Evt6BpRge1mJguzPPmL2BXAKGUgxMdB 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:250352 Archived-At: hokomo writes: > However, pcase-let is less strict about this, producing the same > result with or without the comma: > > (pcase-let ((`(1 _ ,x) '(1 2 3))) > x) > > ;; => 3 > > (pcase-let ((`(1 ,_ ,x) '(1 2 3))) > x) > > ;; => 3 Note this part of the `pcase-let' documentation string: | Each EXP should match (i.e. be of compatible structure) to its | respective PATTERN; a mismatch may signal an error or may go | undetected, binding variables to arbitrary values, such as nil. Your first case is invalid because the pattern doesn't match the value. Here it goes undetected and bindings get established. This behavior is not perfect, but AFAIR it has been preferred over the less efficient code that better checks would mean. So it's the programmer's task to use only matching patterns. This is not really a restriction because `pcase-let' is intended to create bindings, not for testing whether a pattern matches some value. > I think that matching a literal underscore symbol is rare enough that > the ideal behavior would probably be for an underscore within a > backquote template to be treated as a wildcard whenever it appears > literally (e.g., `(1 _)) or unquoted (e.g., `(1 ,_)). However, as soon > as explicitly quoted (e.g., `(1 ,'_)), it should be treated as a match > for a literal underscore symbol. This idea had been discussed in the past. It had some votes but it had been decided not to implement such a feature because it would not really fit into the existing semantics, just for the sake of leaving out one ",". So I'm afraid I don't think we will change this. Michael.