From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: hokomo Newsgroups: gmane.emacs.bugs Subject: bug#59887: pcase vs. pcase-let: Underscore in backquote-style patterns Date: Wed, 07 Dec 2022 17:28:57 +0100 Message-ID: <87sfhrqgxw.fsf@airmail.cc> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24537"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.9; emacs 28.2 To: 59887@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 07 18:10:42 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 1p2xw7-0005iX-21 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Dec 2022 18:10:41 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2xvp-0004mm-AY; Wed, 07 Dec 2022 12:10:05 -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 1p2xvn-0004mX-33 for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 12:10:03 -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 1p2xvm-00068p-Q9 for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 12:10:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p2xvm-0002op-9L for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 12:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: hokomo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Dec 2022 17:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59887 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.167043297310821 (code B ref -1); Wed, 07 Dec 2022 17:10:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Dec 2022 17:09:33 +0000 Original-Received: from localhost ([127.0.0.1]:51145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2xvJ-0002oT-2p for submit@debbugs.gnu.org; Wed, 07 Dec 2022 12:09:33 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:53384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p2xvE-0002oN-UW for submit@debbugs.gnu.org; Wed, 07 Dec 2022 12:09:32 -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 1p2xvE-0004Qz-Nm for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 12:09:28 -0500 Original-Received: from [37.120.193.124] (helo=mail.cock.li) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2xvA-00061t-Ia for bug-gnu-emacs@gnu.org; Wed, 07 Dec 2022 12:09:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=airmail.cc; s=mail; t=1670432957; bh=Vv+K9mEPoe2Vp79v5QU9wVFtqjbfe/BMFG/gFvfvMtI=; h=From:To:Subject:Date:From; b=Za1n/FRpfRahUfa1jK2Gg5+z30gzxPNw+m8n7WMPjtIG+sW+myMQ6JxF/zX1FUqIB 9IubIQJblfJrkoP/amkTdpinuDk6zj+07uPKq6Xqwo8kSN0ewdZO0W8+W17Z0YP3WQ VA3kWhARwMTwek6DXJ6AHhULJJC4667rejpmXn0iSAqRyj66TRSjDtpa0eoW4ypKOE 1NI/YHM7urgiSDPWnKTuAO4L4BLyVPTTs0QBuQMp4vMwKrVNZloxjYfeQauAY4hrhH 9zrCpxmMR40WjQBOEhVuQt5kMkT7EYzU8LkkglDZ2Qu/s6UjCRhSGriOVswNftzT9h Tu9GcbLaebs1A== X-Host-Lookup-Failed: Reverse DNS lookup failed for 37.120.193.124 (failed) Received-SPF: pass client-ip=37.120.193.124; envelope-from=hokomo@airmail.cc; helo=mail.cock.li X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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:250201 Archived-At: Hello, How exactly is the underscore symbol treated in pcase's backquote-style patterns? Seems like at least pcase and pcase-let treat it inconsistently (I haven't checked the other pcase operators). pcase treats the underscore as a literal symbol to match, hence this fails: (pcase '(1 2 3) (`(1 _ ,x) x)) ;; => nil Adding the missing comma in front of the underscore gives us the expected behavior: (pcase '(1 2 3) (`(1 ,_ ,x) x)) ;; => 3 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 Additionally, I would think one would still be able to match a literal underscore symbol even with pcase-let, but the following still ends up matching: (pcase-let ((`(1 ,'_ ,x) '(1 2 3))) x) ;; => 3 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. In other words, I would expect the following would be different from the above: (pcase '(1 2 3) (`(1 _ ,x) x)) ;; => 3 (instead of nil) (pcase-let ((`(1 ,'_ ,x) '(1 2 3))) x) ;; => nil (instead of 3) I'm not 100% sure if these requirements would cause any backwards-incompatible changes or inconsistencies with the other pcase operators though. I'm also assuming that `(1 _) and `(1 ,'_) can be distinguished, but maybe this is not true? hokomo