From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 16 10:05:02 2024 Received: (at submit) by debbugs.gnu.org; 16 Jan 2024 15:05:02 +0000 Received: from localhost ([127.0.0.1]:49433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPkzu-0007FE-10 for submit@debbugs.gnu.org; Tue, 16 Jan 2024 10:05:02 -0500 Received: from lists.gnu.org ([2001:470:142::17]:59156) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPkzs-0007Er-Di for submit@debbugs.gnu.org; Tue, 16 Jan 2024 10:05:01 -0500 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 1rPkzm-0003yv-Hc for bug-gnu-emacs@gnu.org; Tue, 16 Jan 2024 10:04:54 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rPkzh-0004Du-15 for bug-gnu-emacs@gnu.org; Tue, 16 Jan 2024 10:04:54 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id A9F3B240027 for ; Tue, 16 Jan 2024 16:04:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705417484; bh=rmbY0EM1yzxtlzXn9sixFv4fr2rVX2U2laBnhq0bnj0=; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=J+O+GWsmfrsEh5evE3VZpymzA10jtHRZxLFdh+kT0z9mqk4G1/vhiQ86Z/by9sjJH tyYNTs5f+vxg+95uPjQsNpwAmTJIF3paq3deIlnTStNlgomxY3b4FH0QS2Vh5W+539 Yz374liPWtwLnE5JnvZwxsNQy5EfdAPryFmi8EbSfPm/Pz6yj4VRODmIXTNlmQZ4zH hDH0Dm4TkQxoqa7brTB0uEwdw0aMluHFVsLIxpJ2//7oxV4Vkykzfy1dRrn5YSx99V RJrD+gOD9Dbk+O3C41tN4YeiWeD/QXOCEm+de+cfHtZ08GjnHl4W3L6Y5nMHJ2flu5 lNf9E9mBu2Knw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TDsk40dVSz6tvm for ; Tue, 16 Jan 2024 16:04:43 +0100 (CET) From: Ihor Radchenko To: bug-gnu-emacs@gnu.org Subject: 30.0.50; pcase-dolist matches backquote pattern incorrectly X-Debbugs-Cc: Date: Tue, 16 Jan 2024 15:07:57 +0000 Message-ID: <87a5p5l3jm.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Hi, Consider the following (pcase-dolist (`(,(and (pred stringp) a) . ,(and (pred stringp) b)) '(("TODO") ("DONE" . "a"))) (warn "%S :: %S" a b)) Executing the above yields =E2=9B=94 Warning (emacs): "TODO" :: nil =E2=9B=94 Warning (emacs): "DONE" :: "a" even though ("TODO") does not match the pattern. In contrast (dolist (el '(("TODO") ("DONE" . "a"))) (pcase el (`(,(and (pred stringp) a) . ,(and (pred stringp) b)) (warn "%S :: %S" a b)))) correctly displays =E2=9B=94 Warning (emacs): "DONE" :: "a" In GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version 3.24.39, cairo version 1.18.0) of 2024-01-16 built on localhost Repository revision: 5f73258753ee91c8648e0be55332f7dbaea9fa8b Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101010 System Description: Gentoo Linux --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 16 11:52:35 2024 Received: (at 68509) by debbugs.gnu.org; 16 Jan 2024 16:52:35 +0000 Received: from localhost ([127.0.0.1]:49585 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPmfz-0003ji-8N for submit@debbugs.gnu.org; Tue, 16 Jan 2024 11:52:35 -0500 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:53372) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPmfw-0003jV-P4 for 68509@debbugs.gnu.org; Tue, 16 Jan 2024 11:52:34 -0500 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5cf1f4f6c3dso3084363a12.2 for <68509@debbugs.gnu.org>; Tue, 16 Jan 2024 08:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705423946; x=1706028746; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=tdeggJvxVOodRM3G/51HdCQo32MbkdIydgR/x4W5xqM=; b=NhpM49FEPuRovLIh3imNcLsT7y99XgjYoEbWRze9UoxIL+b/HxzKIPPavQEHOHgv5W 6vmvV8XDZSS9Z1tgEu14Uoxqz5oFxZeoGPcFTlXZPYdLc+e7qmgoHDN5rAkOjnqnxqRi SsW5PmUVfhYfe1cDG2LBozXwIyH8qX5JPr4+SQYBkpuUnnfGajZpH9Jw4w8sYoTH0JIM lu98y4JG+lpMi9z7pc552celjcAfNfahcGyDSYQI3eV01sUl/jJTUtS+aSrA7MiBtg3d 7gFBorG03XkPQCHT5e+YhqR9lEFA9e41Jo9H17rq0bX9C1oZ2kOh+ARTalqiNafY0Rf+ K4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705423946; x=1706028746; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tdeggJvxVOodRM3G/51HdCQo32MbkdIydgR/x4W5xqM=; b=nzEnwD+JP6XqFsptcuRXSA3o9T61OCsTai+PkWAMP6Dy46Sb7mmwkftpAMa1+B6Yuc JCK9OVUft8pLF+ug+Ig3dBC3H9+RYh8+sIobgPdsrUkfi0cNfR+J3uzyo2Ehr7bmVypb 4udBLD2s/zun0HCXgFXZrcKOcfYFcaBM6p3V2uZ/wldd1GL0jwwrDkvAJ3s3lmmHzmDC Zo97J+Occ7Bm9KND1swBrNBFp9S3xMz0DIfuNSwzW99X1+nkqFVdGYFdkExLOhbJj3FK aIZqBnX6CGToSPwlHnPGopbDBQWhNYLtoJUPhF2rbNmAuLkooNUngsw6jbM60w6iHWhw y8jw== X-Gm-Message-State: AOJu0YyoAi6mJ58zUiCx8T42yxryMG6dXuOE9hzd/baw2+hQVNJanxWt KKnh2bMC4lvX7mmD6YT1D1o= X-Google-Smtp-Source: AGHT+IEJrJcOANPQMZVLWS/QwV6Xs29cxh4lPdPjEQUSeuGXJBLFLHb1Z70GCa2+Ev57mx2mMVrS/A== X-Received: by 2002:a05:6a20:da9b:b0:199:d6c7:2e44 with SMTP id iy27-20020a056a20da9b00b00199d6c72e44mr3814749pzb.3.1705423946325; Tue, 16 Jan 2024 08:52:26 -0800 (PST) Received: from [192.168.1.2] (076-168-148-233.res.spectrum.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id fh7-20020a056a00390700b006d9b2d86bcasm9558087pfb.46.2024.01.16.08.52.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Jan 2024 08:52:25 -0800 (PST) Message-ID: <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> Date: Tue, 16 Jan 2024 08:52:27 -0800 MIME-Version: 1.0 Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly Content-Language: en-US To: Ihor Radchenko , 68509@debbugs.gnu.org References: <87a5p5l3jm.fsf@localhost> From: Jim Porter In-Reply-To: <87a5p5l3jm.fsf@localhost> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 68509 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 1/16/2024 7:07 AM, Ihor Radchenko wrote: > Consider the following > > (pcase-dolist (`(,(and (pred stringp) a) . > ,(and (pred stringp) b)) > '(("TODO") ("DONE" . "a"))) > (warn "%S :: %S" a b)) > > Executing the above yields > > ⛔ Warning (emacs): "TODO" :: nil > ⛔ Warning (emacs): "DONE" :: "a" > > even though ("TODO") does not match the pattern. This isn't an issue with 'pcase-dolist', but rather a known/intentional limitation of 'pcase-let': (pcase-let ((`(,(and (pred stringp) a) . ,(and (pred stringp) b)) '("TODO"))) (warn "%S :: %S" a b)) -> Warning (emacs): "TODO" :: nil The 'pcase-let' docstring says this: > 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. I do think we should fix it somehow though. This behavior is extremely confusing, and as much as I'm a fan of 'pcase', I'm emphatically *not* a fan of how this part works. From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 16 13:40:39 2024 Received: (at 68509) by debbugs.gnu.org; 16 Jan 2024 18:40:39 +0000 Received: from localhost ([127.0.0.1]:49754 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPoMZ-0008JN-4C for submit@debbugs.gnu.org; Tue, 16 Jan 2024 13:40:39 -0500 Received: from mout02.posteo.de ([185.67.36.66]:39205) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rPoMW-0008J2-T2 for 68509@debbugs.gnu.org; Tue, 16 Jan 2024 13:40:38 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 53E8D240101 for <68509@debbugs.gnu.org>; Tue, 16 Jan 2024 19:40:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705430430; bh=+9lWokKlWPa+YiK+QC93xKekPz+nvfuy1BIU4d4ygrU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=aCjzSkrZA7icpOcSBolEVQLYjSnDsnIqdPS6D2c5CrotUkTnXJ/QLRhPOXx/is0Y5 1gVweGH4zEVRQnafMRBTB6jCrvYvNHt/TTsxsCK/TeolzYFZxy/U96YMn4/CeeZeeT YmAfXGQdWgbwNm8dXDWzMc6qjpuQBnZ0B/tQbU7nyFuGGBjWToXCYRwtRXtUFGTW7j rV65odGwYOkw5n3GJoZ5ycjzS/v3KLy1JbCIVg6Us1P/w12+of9MPCnZXKxt0QojVS l9gH/qihf4F6QXezznbMijlosByQK2Xtit7TFdoSiDPZ4DEOP98OpKb+wlked0GL5l Unxw6Th/bdDgg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TDyW14nmJz6trs; Tue, 16 Jan 2024 19:40:29 +0100 (CET) From: Ihor Radchenko To: Jim Porter Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> Date: Tue, 16 Jan 2024 18:43:45 +0000 Message-ID: <87sf2xjezi.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 68509 Cc: 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Jim Porter writes: > This isn't an issue with 'pcase-dolist', but rather a known/intentional > limitation of 'pcase-let': > > (pcase-let ((`(,(and (pred stringp) a) . > ,(and (pred stringp) b)) > '("TODO"))) > (warn "%S :: %S" a b)) > -> Warning (emacs): "TODO" :: nil > > The 'pcase-let' docstring says this: > >> 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. > > I do think we should fix it somehow though. This behavior is extremely > confusing, and as much as I'm a fan of 'pcase', I'm emphatically *not* a > fan of how this part works. Not sure about pcase-let, but pcase-dolist specifically may be simplified not to use pcase-let: (if (pcase--trivial-upat-p (car spec)) `(dolist ,spec ,@body) (let ((tmpvar (gensym "x"))) `(dolist (,tmpvar ,@(cdr spec)) (pcase ,tmpvar (,(car spec) ,@body))))) -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 05:02:21 2024 Received: (at 68509) by debbugs.gnu.org; 19 Feb 2024 10:02:21 +0000 Received: from localhost ([127.0.0.1]:40392 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc0Td-0002XB-3e for submit@debbugs.gnu.org; Mon, 19 Feb 2024 05:02:21 -0500 Received: from mout01.posteo.de ([185.67.36.65]:45437) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc0TZ-0002Ww-Lz for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 05:02:19 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 5DFFF24002B for <68509@debbugs.gnu.org>; Mon, 19 Feb 2024 11:01:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708336910; bh=6dO1eGIdqETlXJiX0pKaqJk+AGWPlQ1gJdOeKJhtq1M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=h+RQAKsm+hOwqFdn+IEk2d4GtGCHfiGfxq6fav050waGtKkdemSgXnsLikH6iIoQ2 vWKh8NmaIvApjTRYtG65mGzFvmVYo2aaif7n6TxeH39MsUpM3zkY3enyLyumDzT5b/ 8W3/n7wEclu25E+lXxgDbeZARWc3GJ4+sqviNTNNR0Minrg/CXMMwKWK0biH/8KG8Z CSOfZ5JfVYsetHojr2Jkxm0niaBzO01TxBkmvAHGqlCqWP0y5g1wfBnYT2z95Z2Hd4 QRATS3RPV9sK+pI+dXOiPnxKSFujhRgXM7GdHdT4eds2LxUo2qVnP83Ry3RXHRXdhr vndRbPKf1mBoA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TddNs2MKVz6tvJ; Mon, 19 Feb 2024 11:01:49 +0100 (CET) From: Ihor Radchenko To: Jim Porter Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87sf2xjezi.fsf@localhost> References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> Date: Mon, 19 Feb 2024 10:05:33 +0000 Message-ID: <871q98hiqa.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Not sure about pcase-let, but pcase-dolist specifically may be > simplified not to use pcase-let: > > (if (pcase--trivial-upat-p (car spec)) > `(dolist ,spec ,@body) > (let ((tmpvar (gensym "x"))) > `(dolist (,tmpvar ,@(cdr spec)) > (pcase ,tmpvar (,(car spec) ,@body))))) See the attached patch. If the patch is acceptable, we also need to update the manual. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-pcase-let-Skip-LIST-element-that-do-not-match-the-PA.patch >From f3e1362f7687c731e0ba4e410f005252309ffc3f Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Mon, 19 Feb 2024 13:02:21 +0300 Subject: [PATCH] pcase-let: Skip LIST element that do not match the PATTERN (bug#68509) * lisp/emacs-lisp/pcase.el (pcase-dolist): Use `pcase' rather than `pcase-let*' to match the list elements. Update the docstring, describing the behavior when list elements to not match the pattern. The previous undefined behavior is removed. * test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-pcase-dolist): Add new test. --- lisp/emacs-lisp/pcase.el | 13 ++++++------- test/lisp/emacs-lisp/pcase-tests.el | 12 ++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index ae9bd87997c..8dc11b20a6f 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el @@ -329,21 +329,20 @@ pcase-let (defmacro pcase-dolist (spec &rest body) "Eval BODY once for each set of bindings defined by PATTERN and LIST elements. PATTERN should be a `pcase' pattern describing the structure of -LIST elements, and LIST is a list of objects that match PATTERN, -i.e. have a structure that is compatible with PATTERN. +LIST elements, and LIST is a list of objects. For each element of LIST, this macro binds the variables in PATTERN to the corresponding subfields of the LIST element, and -then evaluates BODY with these bindings in effect. The -destructuring bindings of variables in PATTERN to the subfields -of the elements of LIST is performed as if by `pcase-let'. +then evaluates BODY with these bindings in effect. When an element does +not match the pattern, such element is skipped. +The destructuring bindings of variables in PATTERN to the subfields +of the elements of LIST is performed as if by `pcase'. \n(fn (PATTERN LIST) BODY...)" (declare (indent 1) (debug ((pcase-PAT form) body))) (if (pcase--trivial-upat-p (car spec)) `(dolist ,spec ,@body) (let ((tmpvar (gensym "x"))) `(dolist (,tmpvar ,@(cdr spec)) - (pcase-let* ((,(car spec) ,tmpvar)) - ,@body))))) + (pcase ,tmpvar (,(car spec) ,@body)))))) ;;;###autoload (defmacro pcase-setq (pat val &rest args) diff --git a/test/lisp/emacs-lisp/pcase-tests.el b/test/lisp/emacs-lisp/pcase-tests.el index d062965952a..241729c108a 100644 --- a/test/lisp/emacs-lisp/pcase-tests.el +++ b/test/lisp/emacs-lisp/pcase-tests.el @@ -160,4 +160,16 @@ pcase-tests-setq (should-error (pcase-setq a) :type '(wrong-number-of-arguments))) +(ert-deftest pcase-tests-pcase-dolist () + ;; Ignore non-matching elements. + (should + (equal + '(("DONE" . "a")) + (let (result) + (pcase-dolist (`(,(and (pred stringp) a) . + ,(and (pred stringp) b)) + '(("TODO") ("DONE" . "a"))) + (push (cons a b) result)) + (nreverse result))))) + ;;; pcase-tests.el ends here. -- 2.43.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 07:59:47 2024 Received: (at 68509) by debbugs.gnu.org; 19 Feb 2024 12:59:47 +0000 Received: from localhost ([127.0.0.1]:40670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc3FJ-0004l7-Lu for submit@debbugs.gnu.org; Mon, 19 Feb 2024 07:59:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc3FF-0004kp-PK for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 07:59:43 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rc3En-0000vE-Lu; Mon, 19 Feb 2024 07:59:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=jXb2dk+P5wQjbr4buLF9jvXCOtDyChHe7bOMcRThoq0=; b=nFd3HF3A3B6p RWWIvDru4pCcE6+PLM2Fqpxhm5w1h7LfnQzPslGkEEqE41Pc9MA6DFy9r0TIYeDPDhIbHX2e8FejK KUCBqN7xbAPzh/QFH4IkLt+Cg3o6ACESOArg24zlkOPArtA/k/NyiWo+Iuc5uJudTpTGaZB2SVz67 EfaVLubtUXmN7XiLQxbLsu0XX1fQ2EjhKzd9z9y9DLPgjsSYy9wZHZ5zcWVcemSwdV5ncalfamaVN +rr+8Y9Ynvk+DH2rBYZmwW5qROxEG4X89ZSa5ctr/nYmAZ6eDhzrIwuFt7BLVTNsnPj8lQodkGvrc 1NhmylvfLgd9NuTXAA4/0w==; Date: Mon, 19 Feb 2024 14:59:09 +0200 Message-Id: <86sf1opq3m.fsf@gnu.org> From: Eli Zaretskii To: Ihor Radchenko , Stefan Monnier In-Reply-To: <871q98hiqa.fsf@localhost> (message from Ihor Radchenko on Mon, 19 Feb 2024 10:05:33 +0000) Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: jporterbugs@gmail.com, 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) > Cc: 68509@debbugs.gnu.org > From: Ihor Radchenko > Date: Mon, 19 Feb 2024 10:05:33 +0000 > > Ihor Radchenko writes: > > > Not sure about pcase-let, but pcase-dolist specifically may be > > simplified not to use pcase-let: > > > > (if (pcase--trivial-upat-p (car spec)) > > `(dolist ,spec ,@body) > > (let ((tmpvar (gensym "x"))) > > `(dolist (,tmpvar ,@(cdr spec)) > > (pcase ,tmpvar (,(car spec) ,@body))))) > > See the attached patch. > If the patch is acceptable, we also need to update the manual. Thanks. Adding Stefan to the discussion. From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 10:52:17 2024 Received: (at 68509) by debbugs.gnu.org; 19 Feb 2024 15:52:17 +0000 Received: from localhost ([127.0.0.1]:43226 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc5wH-00074J-86 for submit@debbugs.gnu.org; Mon, 19 Feb 2024 10:52:17 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:21646) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc5wE-00073y-Jk for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 10:52:16 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 5C85080841; Mon, 19 Feb 2024 10:51:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708357906; bh=HnwDE3qOsqFUF6iDe7RSQV628u7qjsYVDE6m+yh/gII=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=nRdDw3lRv2qVGfxEONaSnuYV9rbLuBm3GRxWZZFvQJoRqsvh76vmm1xRW3P1J/2XR raUUrSaTSHXmqqQeAXAUSQMYsG83i4EiPjcpZfBNRyJ0ZnvWMSBtbSN0P3iu++P1Ex Y9LAmh0rluLKwNrwLN1rCg6+r4Q666O4jYD7L82ZOdT/eMeHCsIPD8942qCdc66NQO z1ynQ3uC1kgUuj+ZC5IVRxEINIuOIfpqgA5WzkVIBfgkNCYeGa6bwAt6Fwo2IaPAxy sQOrevskJU6+5K3YHiiZLjwmm89rIgXRQElOuFCztVOJxww7516jXStJWP1s/cskYd /Pu97eQ8LwUdQ== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 522548014F; Mon, 19 Feb 2024 10:51:46 -0500 (EST) Received: from milanesa (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2976E12012E; Mon, 19 Feb 2024 10:51:46 -0500 (EST) From: Stefan Monnier To: Jim Porter Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> (Jim Porter's message of "Tue, 16 Jan 2024 08:52:27 -0800") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> Date: Mon, 19 Feb 2024 10:51:45 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.009 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Ihor Radchenko , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) >> Consider the following >> (pcase-dolist (`(,(and (pred stringp) a) . >> ,(and (pred stringp) b)) >> '(("TODO") ("DONE" . "a"))) >> (warn "%S :: %S" a b)) >> Executing the above yields >> =E2=9B=94 Warning (emacs): "TODO" :: nil >> =E2=9B=94 Warning (emacs): "DONE" :: "a" >> even though ("TODO") does not match the pattern. > > This isn't an issue with 'pcase-dolist', but rather a known/intentional > limitation of 'pcase-let': Indeed, I consider the above a pilot error. `pcase-dolist` and `pcase-let` use Pcase patterns to do *destructuring*, which is a different task than the one done by `pcase` (which decides whether a value matches a pattern or not). >> 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. > I do think we should fix it somehow though. This behavior is > extremely confusing, and as much as I'm a fan of 'pcase', I'm > emphatically *not* a fan of how this part works. I'm quite happy with the way it works when you use it as intended. But I'm not really satisfied either with the way it behaves when the coder doesn't understand its semantics, nor about the way we document that semantics. The difficulty in resolving this can be illustrated with the following pattern: `(a . ,b) This pattern leads to two tests: (consp VAL) and (eq 'a (car VAL)). When destructuring, we want to throw away both tests (we want to throw away most tests, except those needed to choose between two `or` branches). We could decide to emit a warning because we silently skip the `eq` test, which would help the coders understand that the pattern doesn't do what they think. But emitting that same warning because we silently skip the `consp` test would be really annoying because rewriting the pattern to avoid this is impractical. For a human, it's pretty easy to distinguish those two cases. But it's difficult to provide a precise definition that distinguishes those two case= s. We could also keep the tests and emit a warning or even an error when they fail, but if that's the behavior you want, then you should arguably use `pcase(-exhaustive)` instead. Stefan From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 10:54:29 2024 Received: (at 68509) by debbugs.gnu.org; 19 Feb 2024 15:54:29 +0000 Received: from localhost ([127.0.0.1]:43237 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc5yP-00079e-7s for submit@debbugs.gnu.org; Mon, 19 Feb 2024 10:54:29 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:35694) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc5yN-00079M-OO for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 10:54:28 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 42DFA80841; Mon, 19 Feb 2024 10:54:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708358040; bh=EL6SpcDxeOlFQBl9FxNTlWrjTYiWIL/WJLprmW+cpXM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=QXzMu98DaYhlRzrLY1z+mIBYzcnMAPJeAAKADTXdBxvcgtgpWALPbwt9rsQZClcfj U+SE1v6IELnsZQhB+NoYOYDQYaf96xRcppKCefdb7modkubzGBEJIrCUsaw/vYWxVZ /ZkGLU77an7+CoijxA8e4s8hpBM0CqsptlM3EJKu+ZcjqizHXBifw9l+3j1v9tJso+ /Zo8bUs1Oz7c2RkPGQUGnIbo15J8NeqM+Mbfz+W64u+Om+duzFEXBKhjqQf9nsK37Q W1l5rZykIxpaPbTOSDd0t4CIOsX5jVSPstQVlFiv3X5/EuLXzlt0BN2tepLPXbA53Q /uqweT9I6RimA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 5A3EB8014F; Mon, 19 Feb 2024 10:54:00 -0500 (EST) Received: from milanesa (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 38B5212008F; Mon, 19 Feb 2024 10:54:00 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <871q98hiqa.fsf@localhost> (Ihor Radchenko's message of "Mon, 19 Feb 2024 10:05:33 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> Date: Mon, 19 Feb 2024 10:53:59 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.009 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) > * lisp/emacs-lisp/pcase.el (pcase-dolist): Use `pcase' rather than > `pcase-let*' to match the list elements. Update the docstring, That changes its behavior. It *will* break code. This is basically not the same macro any more. Instead of being a macro that iterates over all the elements of the list, it becomes a macro which iterates only over the matching elements. Stefan From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 13:11:18 2024 Received: (at 68509) by debbugs.gnu.org; 19 Feb 2024 18:11:18 +0000 Received: from localhost ([127.0.0.1]:43366 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc86n-0005Wy-Sl for submit@debbugs.gnu.org; Mon, 19 Feb 2024 13:11:18 -0500 Received: from mout01.posteo.de ([185.67.36.65]:43813) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc86j-0005Wg-SN for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 13:11:16 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 5F557240029 for <68509@debbugs.gnu.org>; Mon, 19 Feb 2024 19:10:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708366246; bh=2FQnKErhc8XFVS9Onp/2M6izh9AC9taH46Msa/sAONg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=KbeC5WV9ZQct9i/nzqK+Dw0OIaZb4v/R1e1HaZBQOfROWG7BLF9U7Vs6I2mI7hid2 Iw0FbyuF8UPrS1DhmpIPPdgaxPpK2yq2IU17sE7gTkNfMaMofZDzH39m4fRNdWaCvQ U15vGJmzM/Rzhn7QEeN2jdMFsqjU/IEwU75z5oEguqzxIcTdT52vMXPsQ0vnPN6hAn ZXuJQKRojGina/mHokI9Gfsj39M1eyLR967zs49Sg9/Ix1LAxH1ox3f1WBm49C0Sn7 cs2ep0et5cGVrnJO18aCxV3h1qts+yBhm65JjWa4uyLE1PCH4LmXGPpkydtyri/aco xNf3V64xVX9eg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TdrF14RYnz6tvb; Mon, 19 Feb 2024 19:10:44 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> Date: Mon, 19 Feb 2024 18:14:24 +0000 Message-ID: <8734to8gov.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) Stefan Monnier writes: >> * lisp/emacs-lisp/pcase.el (pcase-dolist): Use `pcase' rather than >> `pcase-let*' to match the list elements. Update the docstring, > > That changes its behavior. It *will* break code. > This is basically not the same macro any more. Instead of being a macro > that iterates over all the elements of the list, it becomes a macro > which iterates only over the matching elements. Currently, the docstring states: PATTERN should be a `pcase' pattern describing the structure of LIST elements, and LIST is a list of objects that match PATTERN, i.e. have a structure that is compatible with PATTERN. It is undefined what happens when LIST objects do not match PATTERN. So, any code relying upon iterating over non-matching elements is relying upon undefined, undocumented behaviour. Moreover, current implementation binds /partially matching/ list elements, which is even more fragile. From `pcase-let' docstring: a mismatch may signal an error or may go undetected, binding variables to arbitrary values, such as nil. What I suggest is to change what happens when PATTERN does not much more explicitly. In my patch, I proposed to skip such elements. An alternative could be throwing an error. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 13:13:25 2024 Received: (at 68509) by debbugs.gnu.org; 19 Feb 2024 18:13:25 +0000 Received: from localhost ([127.0.0.1]:43371 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc88q-0005a1-I9 for submit@debbugs.gnu.org; Mon, 19 Feb 2024 13:13:24 -0500 Received: from mout02.posteo.de ([185.67.36.66]:50349) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rc88o-0005Zo-1G for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 13:13:23 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 736C0240103 for <68509@debbugs.gnu.org>; Mon, 19 Feb 2024 19:12:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708366374; bh=941w/mre/xBNWnY3p0jVYgUMGeTLkGzQdl/X6DZy4ME=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=gspBKVtH4z+GXRFAnbU9wA2sZ5n5zk/34L+ynPrY/5MO51Xsmcy8w6vG8urYEWz8E 1PsQp5q/Ar4QpwBINBr6BAqprKoIbfjvh+bYlMHZLfa5DlIDtvcMqtEEpDhyxwS6df nYupfKmoTLIrJ7TWL7GPHGCFXJxkp3ypCNfOyBbfMqOxxtOxRQiIPaqXtdoXtXcMl3 PBGfzQPufNBLLDdZ191wVReoxx4OeRIlNCdYeax/k5ZjWGl7uIzOwoJNDkXwysN3+T NslYf96lr9y03Yt9qvhLdhhB8yqNfXMUgDaXjyx72Lti8dQBRkDNqlJ1qRLyJSVNnk tTIk6QjHy3HgA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TdrHT4sJ1z6twJ; Mon, 19 Feb 2024 19:12:53 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> Date: Mon, 19 Feb 2024 18:16:37 +0000 Message-ID: <87zfvw720q.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) Stefan Monnier writes: > The difficulty in resolving this can be illustrated with the following > pattern: > > `(a . ,b) > > This pattern leads to two tests: (consp VAL) and (eq 'a (car VAL)). > When destructuring, we want to throw away both tests (we want to throw > away most tests, except those needed to choose between two `or` > branches). > > We could decide to emit a warning because we silently skip > the `eq` test, which would help the coders understand that the pattern > doesn't do what they think. > But emitting that same warning because we silently skip the `consp` test > would be really annoying because rewriting the pattern to avoid this > is impractical. May you please elaborate how this example is related to destructuring from user perspective? It appears to me that you are talking about implementation details of `pcase', which are elusive to me. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 21:42:15 2024 Received: (at 68509) by debbugs.gnu.org; 20 Feb 2024 02:42:15 +0000 Received: from localhost ([127.0.0.1]:43962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcG5G-0005Sl-Ik for submit@debbugs.gnu.org; Mon, 19 Feb 2024 21:42:15 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:34452) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcG5E-0005SW-EI for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 21:42:13 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 43C5E442739; Mon, 19 Feb 2024 21:41:45 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708396903; bh=G+NueyJXDE25snu//F9695I7hPNIAFOHe8lxTMafGdU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=P+5qLUxX5WGjcApLCIpZMDlWHEUdBjZ08kftpdtvy5PIYIX3q/tWfqdBrd30CSnFg GRgGEXNQ7ck3DWDxCXNuXx4o/OvFQSSe5c9vgnJfKu42nAFkVdH2kG+G85PrZLRg5n 0GbL7MO0FHn/zmWl9l8yik59X+l/uxPgiLACdlW4Xlcqe+JJkRun3eBa/jEYb7bDB1 NexN8Y3oKm+RC0skkM5DVc194g2HvWY43jklAhC5JOyZL2Ei+QJ4VU586pMHZdm13F huncnEiDqHnQoBzwhHo0DKgAIB3kVKSkzSMF1OpzmPgQgZmhFe3Q34zI9gP67PLCTn vS/Agp9oAsbwA== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D1F50442711; Mon, 19 Feb 2024 21:41:43 -0500 (EST) Received: from pastel (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AC5E11202AB; Mon, 19 Feb 2024 21:41:43 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <8734to8gov.fsf@localhost> (Ihor Radchenko's message of "Mon, 19 Feb 2024 18:14:24 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> Date: Mon, 19 Feb 2024 21:41:43 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.002 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) Ihor Radchenko [2024-02-19 18:14:24] wrote: > Stefan Monnier writes: > >>> * lisp/emacs-lisp/pcase.el (pcase-dolist): Use `pcase' rather than >>> `pcase-let*' to match the list elements. Update the docstring, >> >> That changes its behavior. It *will* break code. >> This is basically not the same macro any more. Instead of being a macro >> that iterates over all the elements of the list, it becomes a macro >> which iterates only over the matching elements. > > Currently, the docstring states: > > PATTERN should be a `pcase' pattern describing the structure of > LIST elements, and LIST is a list of objects that match PATTERN, > i.e. have a structure that is compatible with PATTERN. The doc for `pcase-let` is a bit more precise: 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. > In my patch, I proposed to skip such elements. > An alternative could be throwing an error. As I said, what you propose is a *different* construct. Maybe we should add some extra option/keyword to `pcase-dolist` to indicate what to do with elements that don't match (such as signaling an error, a warning, silently skipping it, ...). Similar issues affect `pcase-let`, of course. Stefan From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 19 21:46:43 2024 Received: (at 68509) by debbugs.gnu.org; 20 Feb 2024 02:46:43 +0000 Received: from localhost ([127.0.0.1]:43979 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcG9a-0005as-QP for submit@debbugs.gnu.org; Mon, 19 Feb 2024 21:46:43 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:34556) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcG9Z-0005ae-8D for 68509@debbugs.gnu.org; Mon, 19 Feb 2024 21:46:41 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 6D197807A5; Mon, 19 Feb 2024 21:46:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708397173; bh=+bdrvZ7HrdjP8tBy6xq5R/tx6EAbgRBAMIJa9oLRti8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=DrKcEaJW2oj6t9kNZJm1bcV3LT2OeH257XDnpboaPAZBsFDjqn/umFgz55dLxemFJ Pf9gmDNz6Eo2gkSToNk26z/exWF+mUmuiEakRTG6RLWPPHpjUyMIbrsS9VIvDN9yGE CJi+BHI4sVJVzniWeQrpdWSt34NuCLsaRrxZwE3+EX4EEz2a0HavGQHzbjnvNuf68X OdUrOlSNnuDU/c+6HgcYuQiBwMtWto2s9xzjqlt652Q5S5rF15JOUQDjTo4HramTu7 0dQ36TxaMZ+j4lJl9N3WprY9ggVjVvHrHID/NZ7KWr7Q3I2dRJGu5UpLBQfuAENhWE PmcxcKJHWdOBQ== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 7EE1F8014F; Mon, 19 Feb 2024 21:46:13 -0500 (EST) Received: from pastel (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 553DE120776; Mon, 19 Feb 2024 21:46:13 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87zfvw720q.fsf@localhost> (Ihor Radchenko's message of "Mon, 19 Feb 2024 18:16:37 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87zfvw720q.fsf@localhost> Date: Mon, 19 Feb 2024 21:46:12 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.049 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) >> The difficulty in resolving this can be illustrated with the following >> pattern: >> >> `(a . ,b) >> >> This pattern leads to two tests: (consp VAL) and (eq 'a (car VAL)). >> When destructuring, we want to throw away both tests (we want to throw >> away most tests, except those needed to choose between two `or` >> branches). >> >> We could decide to emit a warning because we silently skip >> the `eq` test, which would help the coders understand that the pattern >> doesn't do what they think. >> But emitting that same warning because we silently skip the `consp` test >> would be really annoying because rewriting the pattern to avoid this >> is impractical. > > May you please elaborate how this example is related to destructuring > from user perspective? It appears to me that you are talking about > implementation details of `pcase', which are elusive to me. I'm just reading aloud what the `(a . ,b) pattern means: it means "VAL has to be a cons, and its car should be equal to `a`" (and in addition to that, we'll extract the `cdr` and put it into the `b` variable). We might want to warn the user that such a pattern in `pcase-let` and `pcase-dolist` is probably an error because the `a` won't actually be checked, so it will behave just like the `(,_ . ,b) pattern. But warning the user that the `consp` check will also be dropped would be annoying because it's not like the users can easily write a different pattern that still behaves the same but does not imply such a `consp` check. Stefan From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 20 08:37:43 2024 Received: (at 68509) by debbugs.gnu.org; 20 Feb 2024 13:37:43 +0000 Received: from localhost ([127.0.0.1]:44543 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcQJb-000112-Ev for submit@debbugs.gnu.org; Tue, 20 Feb 2024 08:37:43 -0500 Received: from mout01.posteo.de ([185.67.36.65]:42309) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcQJY-00010n-TZ for 68509@debbugs.gnu.org; Tue, 20 Feb 2024 08:37:42 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 7561B240027 for <68509@debbugs.gnu.org>; Tue, 20 Feb 2024 14:37:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708436232; bh=uYyhF4W3hSfUe4jx9jc1+3ZzndGQrDudhaBC0oIC9Xg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=B3hyE3yG+tqdPS5eAAipcZoLctekq5qsMjZ+SSNtDkPBNnRpbioD7/MOhzLHZelz0 5ZV+ojuBp4pn/V2sdmY7smtRAr2E941Q0l3YVTqcG8dgyH9r1weQ6FrbtFbc/BHvuW QeaEuPakzI9f0ukVKQQ3Hn9oOFEeROCIH2kWlO6IJ0+eHpbcemMc6SPDjTn+t+Md/0 l+lZ8jYCwXGlfnSkA6SRYUoPhSwf8kW7hcAA3inFR/B/13SuWoffWxZO2xxYJgd5h9 1txISbYoraf7h/fTqOhc+pmKGkPQSINh3oTt35rQt60V43qqKaJHbH8nQsL9x6sGjz 2f2IEFC+wp70A== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TfL6v0ZKcz9rxD; Tue, 20 Feb 2024 14:37:10 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> Date: Tue, 20 Feb 2024 13:40:52 +0000 Message-ID: <87o7cbz21n.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) Stefan Monnier writes: >> In my patch, I proposed to skip such elements. >> An alternative could be throwing an error. > > As I said, what you propose is a *different* construct. > Maybe we should add some extra option/keyword to `pcase-dolist` to > indicate what to do with elements that don't match (such as signaling > an error, a warning, silently skipping it, ...). > > Similar issues affect `pcase-let`, of course. What about adding extra option/keyword and also showing a runtime warning when pcase-dolist/pcase-let encounter something that does not match the pattern? In such situation, the code logic probably has a problem that is worth highlighting. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 20 09:36:36 2024 Received: (at 68509) by debbugs.gnu.org; 20 Feb 2024 14:36:36 +0000 Received: from localhost ([127.0.0.1]:44658 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcREZ-0002Yl-OJ for submit@debbugs.gnu.org; Tue, 20 Feb 2024 09:36:36 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:3885) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcRET-0002YU-Kk for 68509@debbugs.gnu.org; Tue, 20 Feb 2024 09:36:33 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 64CF1441365; Tue, 20 Feb 2024 09:36:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708439760; bh=VembNqd3VqVLMqT+SSgYzQKc+J8TwKRKlzjT+JoXr8k=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=kEGF0NUC/7FCK5W/IIsiSohWdQXQTJ3tL06ZVw/9K/kAFIFrTiBEP2MWDjAJBZuI1 NwmI3ytfic6CzV0QiROipvS4lhS46FYD7ccpYs45487c4MQPQhuy8JE5cx2M9qJMId 1TmzK+E2L+LkuMeYg8c8tLTNlNqa+O+28jzGEQiaPHXlzrqHbAdfjs2TKaFbY/mIBo PyMZ6NHIrc69GSRMJFCqUzFl/3qKw9cjlz8dOXT0rbdvHWhBQFIcLxOLNiCgF049NL x2ojiDIkkz/6jcWiYelR8OfxhvogMcBpBvjF6DC5o5qWuJyUotp//8Tcs+2hMmkmGh xg0HremD949Uw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 453DF44134D; Tue, 20 Feb 2024 09:36:00 -0500 (EST) Received: from pastel (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 1D1E512008F; Tue, 20 Feb 2024 09:36:00 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87o7cbz21n.fsf@localhost> (Ihor Radchenko's message of "Tue, 20 Feb 2024 13:40:52 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> Date: Tue, 20 Feb 2024 09:35:59 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) > What about adding extra option/keyword and also showing a runtime > warning when pcase-dolist/pcase-let encounter something that does not > match the pattern? In the current use of those primitives, it's routine/normal/common for a pattern like `(,a ,b) to encounter lists of different length than 2, so a warning should be emitted only if specifically requested via an option/keyword. I think it would be OK to emit a warning (even if not specifically requested via an option/keyword) when a value like (help . me) fails to match `(a . ,b), but as mentioned I don't know a good way to distinguish those two kinds of cases. Stefan From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 20 10:13:42 2024 Received: (at 68509) by debbugs.gnu.org; 20 Feb 2024 15:13:42 +0000 Received: from localhost ([127.0.0.1]:46358 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcRoT-0003x6-JX for submit@debbugs.gnu.org; Tue, 20 Feb 2024 10:13:42 -0500 Received: from mout02.posteo.de ([185.67.36.66]:42037) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcRoN-0003wo-Nt for 68509@debbugs.gnu.org; Tue, 20 Feb 2024 10:13:39 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id CFFE4240101 for <68509@debbugs.gnu.org>; Tue, 20 Feb 2024 16:13:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708441987; bh=wReksmAxynpsNMOYL58CXJjaa3QY4MTgNPR9emEyg5o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=U1l17Rm016RKvLfE9VRMvFJTK2x4UbBASvq4R/Ajbp3Dr+uBr3R0Bh4RIbXDbSG+s YQJeavr6XDKXYBiOO2THB4vJZnJLKVNQ0xq1YxvZ57B/pPipMpe1cqdpA1PmfPde5j Xs1CKace2xWUMbeBtjJPx7+B/3DXBxUEhmt58Ma/OJEAf5E1f/COJUBw287prBxg1A TtYXe1swnud9G6DtDBGJJWsxqYESJluUXF4qlsIKntd2xHBxgCY2jY2lXs6TQPJ7Ll wd5vzHKL94EO/DGXq6z3z7JsaLAwdFPSo9S95HfAgeaT6v2jTfPLpqkUpQ//6jhWS+ dbsEojpSm0ojA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TfNFZ4NmXz6tvr; Tue, 20 Feb 2024 16:13:06 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> Date: Tue, 20 Feb 2024 15:16:44 +0000 Message-ID: <87jzmzyxlv.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) Stefan Monnier writes: >> What about adding extra option/keyword and also showing a runtime >> warning when pcase-dolist/pcase-let encounter something that does not >> match the pattern? > > In the current use of those primitives, it's routine/normal/common for > a pattern like `(,a ,b) to encounter lists of different length than 2, > so a warning should be emitted only if specifically requested via an > option/keyword. But isn't it undocumented? -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 20 12:52:34 2024 Received: (at 68509) by debbugs.gnu.org; 20 Feb 2024 17:52:34 +0000 Received: from localhost ([127.0.0.1]:46495 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcUIE-00087u-DM for submit@debbugs.gnu.org; Tue, 20 Feb 2024 12:52:34 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:50735) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcUI8-00087T-R2 for 68509@debbugs.gnu.org; Tue, 20 Feb 2024 12:52:32 -0500 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 0FD551000C3; Tue, 20 Feb 2024 12:52:01 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708451520; bh=cFblzX1YyRwYGtWyIPBhkFvvg05oJ16v5QFMgE8FAsQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=W/rzQDBn3qgyBb05cn7ofM//Bzp5JspTUPFFWO3u3mlSFgKXPvfwDM+r76zveAlvU 4wCM910397K4Mt736UxYRQXR8P7vHdv5iZG7p/8tZ6Vjd5C/vyU96tqiQz7eA5kq/o T3I6QMKHuyuWJq89ngdqC+GHkrBaHJiwfVD5nbrsRGYmDuoghr9bPKdy9DBIVLjC3x NC0Dh1KB9huWgZUGg7nd2V1vukd5Hdnrr+LVmvkBBjRrZWyt9U+RIc3ASJS5slhoL0 kbPaLgKqkxgEyRe68gc3fk2kjW9f6wl9a7w9ffc5bbRpSGKXZCFWUlLQsqCybdg1wr JMP4aO6ngNQ+Q== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 11EA010004B; Tue, 20 Feb 2024 12:52:00 -0500 (EST) Received: from alfajor (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E97E112067B; Tue, 20 Feb 2024 12:51:59 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87jzmzyxlv.fsf@localhost> (Ihor Radchenko's message of "Tue, 20 Feb 2024 15:16:44 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> Date: Tue, 20 Feb 2024 12:51:59 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.052 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) >>> What about adding extra option/keyword and also showing a runtime >>> warning when pcase-dolist/pcase-let encounter something that does not >>> match the pattern? >> In the current use of those primitives, it's routine/normal/common for >> a pattern like `(,a ,b) to encounter lists of different length than 2, >> so a warning should be emitted only if specifically requested via an >> option/keyword. > But isn't it undocumented? AFAIK the "best" documentation we have for that is the one in `pcase-let`, which is indeed unsatisfactory. Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 21 06:20:07 2024 Received: (at 68509) by debbugs.gnu.org; 21 Feb 2024 11:20:07 +0000 Received: from localhost ([127.0.0.1]:47948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rckdy-0001q7-J3 for submit@debbugs.gnu.org; Wed, 21 Feb 2024 06:20:07 -0500 Received: from mout02.posteo.de ([185.67.36.66]:46533) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rckdv-0001pV-Lx for 68509@debbugs.gnu.org; Wed, 21 Feb 2024 06:20:05 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id BF93C240101 for <68509@debbugs.gnu.org>; Wed, 21 Feb 2024 12:19:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708514375; bh=klRRHEAd9dlNa9Vql8Se347BFZtrNHNAAQn8E8Y2pMU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=AxLGldjx4ZHCZMYogv5xKu2qP0gFhGOEsHEhhHUy6aAAowga46y+lxsn0nGTlzsZa THQAkoS+TQ65NgtwjfI1g03n8peyv4R1wlvG2Ru+Ipxm5jWe4ycU2yGe/fZIDtNLoa mG6BTDEwY4/Dw54Uu1CXKC8LQT2kh9Q3nKFgcIDh5vLXJZI8zc3qIa/Afw+oGBsaVR Ah8yDMuync1EzmUPbQOBCqEjBqlSqWun9GjnJZmaHhhli7wFUVsEMuAGfUmiN6yjxf zFer2VAKiraPifPqgp6A+F1JGnMhoIEhD4TsyiqERrUN/Yay0XJuuWekszf3E/Yq9y VSbXcg9UayCkw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Tfv1f5GlKz9rxP; Wed, 21 Feb 2024 12:19:34 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> Date: Wed, 21 Feb 2024 11:23:17 +0000 Message-ID: <87y1berrh6.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) Stefan Monnier writes: >>> In the current use of those primitives, it's routine/normal/common for >>> a pattern like `(,a ,b) to encounter lists of different length than 2, >>> so a warning should be emitted only if specifically requested via an >>> option/keyword. >> But isn't it undocumented? > > AFAIK the "best" documentation we have for that is the one in > `pcase-let`, which is indeed unsatisfactory. May you then describe in more details what is the intended behavior when PATTERN does not match VALUE in destructuring? -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 21 09:18:07 2024 Received: (at 68509) by debbugs.gnu.org; 21 Feb 2024 14:18:07 +0000 Received: from localhost ([127.0.0.1]:48046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcnQF-0001Hh-8L for submit@debbugs.gnu.org; Wed, 21 Feb 2024 09:18:07 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:44557) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcnQA-0001H8-PV for 68509@debbugs.gnu.org; Wed, 21 Feb 2024 09:18:05 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id E1D38440BB6; Wed, 21 Feb 2024 09:17:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708525052; bh=dfCFibtlifrE/YYKmOYQPxJjPRV2sFBrvJ3JBooy7Ao=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=R3FLjiZ6wotfxRJ45KRez7z9a9TxceO7yZKPw3ddqLVJoAxsoSLEfzFwQZqIsMAj/ erMBx3mC/UI1KLNX7KocNvFarS5UHRxsvPZhFkPb163/WI34mLsK2y+e20sUk799Fo MhK06CqhJ6XY15DX6QQcxTiThoEJrPrIcrjZ5HTGjEe1Tc84bEk+L6upPXDsu9hvdE AyOF6/k+0SouxJFgSPzp5S4/TM8rkc8XhJwpiTpPZgTmoDjjBrF9olTg9Ui9BOFC4H /Aq4IGW3bBboo8YE3fjrkYxzaZFW7HLsqwbL2VYVHGP5GavHCCXMTlt07p+WngfCgJ mdPSHAj/nlkMw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5BA7A44024D; Wed, 21 Feb 2024 09:17:32 -0500 (EST) Received: from milanesa (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2A288120679; Wed, 21 Feb 2024 09:17:32 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87y1berrh6.fsf@localhost> (Ihor Radchenko's message of "Wed, 21 Feb 2024 11:23:17 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> <87y1berrh6.fsf@localhost> Date: Wed, 21 Feb 2024 09:17:30 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.2 (-----) >>>> In the current use of those primitives, it's routine/normal/common for >>>> a pattern like `(,a ,b) to encounter lists of different length than 2, >>>> so a warning should be emitted only if specifically requested via an >>>> option/keyword. >>> But isn't it undocumented? >> >> AFAIK the "best" documentation we have for that is the one in >> `pcase-let`, which is indeed unsatisfactory. > > May you then describe in more details what is the intended behavior when > PATTERN does not match VALUE in destructuring? How 'bout the patch below? Stefan diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 78ad5b68a51..cf60cabe52b 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi @@ -1317,11 +1317,18 @@ Destructuring with pcase Patterns does the same as the previous example, except that it directly tries to extract @code{x} and @code{y} from @code{my-list} without first verifying if @code{my-list} is a list which has the right number of -elements and has @code{add} as its first element. The precise -behavior when the object does not actually match the pattern is -undefined, although the body will not be silently skipped: either an -error is signaled or the body is run with some of the variables -potentially bound to arbitrary values like @code{nil}. +elements and has @code{add} as its first element. + +The precise behavior when the object does not actually match the pattern +depends on the types, although the body will not be silently skipped: +either an error is signaled or the body is run with some of the +variables bound to arbitrary values like @code{nil}. +For example, the above pattern will result in @var{x} and @var{y} +being extracted with operations like @code{car} or @code{nth}, so they +will get value @code{nil} when @var{my-list} is too short. In contrast, +with a pattern like @code{`[add ,x ,y]}, those same variables would +be extracted using @code{aref} which would signal an error if +@var{my-list} is not an array or is too short. The pcase patterns that are useful for destructuring bindings are generally those described in @ref{Backquote Patterns}, since they From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 23 09:19:15 2024 Received: (at 68509) by debbugs.gnu.org; 23 Feb 2024 14:19:15 +0000 Received: from localhost ([127.0.0.1]:41233 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdWOQ-0005Vx-Gx for submit@debbugs.gnu.org; Fri, 23 Feb 2024 09:19:14 -0500 Received: from mout01.posteo.de ([185.67.36.65]:42865) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdWOO-0005Vh-Gj for 68509@debbugs.gnu.org; Fri, 23 Feb 2024 09:19:13 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 65A0F240027 for <68509@debbugs.gnu.org>; Fri, 23 Feb 2024 15:01:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708696897; bh=N3sXhwzMlRPHawtNpjMdv5IatGGBMi6ZLCyFPcjVygM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=pVBcZ/dpdIZaAaAdl6UVXLh42Z2v/iuXREw3TkZFpmBl0epy5smZ8DUA3XjuD3J+h nx+heC2Swli1B5frRg2MPFHv3/GRUZxv7cw3GwUG1NSEC4GIC8LsCz4+u0uoRNwB5X XnAMpSeTJRJs/AG1ooefHPDljyS0eQfwVaQqe8KeAGdkqjfo/SHtp2ZDxs14ccayfj s3eaLYDTryxpGKkEhtKtdV1uJbkqtkYlpaWlzo+zGGn5HE/wMC/0seUj7vjNyDX1Fh oabTXm5ZVAi5f3n60P5axLHiHQh83C6fO6A15fdicc41bL8OreqFmy4iQft6URCAvm M6pCdGkStaR5A== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4ThBWg645xz9rxW; Fri, 23 Feb 2024 15:01:35 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> <87y1berrh6.fsf@localhost> Date: Fri, 23 Feb 2024 14:05:19 +0000 Message-ID: <87bk87i8dc.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Stefan Monnier writes: >> May you then describe in more details what is the intended behavior when >> PATTERN does not match VALUE in destructuring? > > How 'bout the patch below? > ... > +The precise behavior when the object does not actually match the pattern > +depends on the types, although the body will not be silently skipped: > +either an error is signaled or the body is run with some of the > +variables bound to arbitrary values like @code{nil}. > +For example, the above pattern will result in @var{x} and @var{y} > +being extracted with operations like @code{car} or @code{nth}, so they > +will get value @code{nil} when @var{my-list} is too short. In contrast, > +with a pattern like @code{`[add ,x ,y]}, those same variables would > +be extracted using @code{aref} which would signal an error if > +@var{my-list} is not an array or is too short. This is confusing. In particular, "for example" implies that other situations are possible. It is unclear how the reader will know when "variables bound to arbitrary values" happen, when variables are bound to nil, and when an error is signaled. I would re-structure the paragraph, explicitly listing the possible outcomes when the PATTERN does not match VALUE and stating that any other non-matching PATTERN will lead to undefined outcome. Also, with the current behavior of `pcase-let', it appears to be impossible to distinguish between too short list (1 2 3) and (1 2 3 nil nil) when assigning destructuring pattern. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 23 09:59:31 2024 Received: (at 68509) by debbugs.gnu.org; 23 Feb 2024 14:59:31 +0000 Received: from localhost ([127.0.0.1]:46021 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdX1O-00085u-LU for submit@debbugs.gnu.org; Fri, 23 Feb 2024 09:59:31 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39004) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdX1M-00085V-Qg for 68509@debbugs.gnu.org; Fri, 23 Feb 2024 09:59:29 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id DA27A4416AA; Fri, 23 Feb 2024 09:58:58 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708700337; bh=xBjF6abgLZ2QAzJvsw24b4VjKpltBb/pgg5rbj8ZLe0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=UdH/wxGW/UWu59mdZTP/CdnRiXdcrtoPTS1VT9b0Iu1AnnkVp1lQ6/oid48el5QVD yhCj9xvUXBYYbLIYUXDO6RRJzichifpMh+Mmt8GN7UUDJmGIRE9LNlnMTnkpIk2d/t 27xnRNmkK0JA7kA5LhKcaFVfUc1MB4Z9a3iBw3L2C8EuHaRnKZl6iyzm5rxOcX9py1 V+zLCTlr5qyBMcdmNYVfCqxGK5l49QjVAmtIBqtm8VMnwQTtly/lUX0kMZXh2TZsls MqAxBGACOYHPeieVUblfAIUikliXWZ+XKWxuFiQBnHwU5CLMGqbnf67bTDp0WEK0YH EM8r5zUZ6NjUw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 4A6DD4416DB; Fri, 23 Feb 2024 09:58:57 -0500 (EST) Received: from alfajor (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 2B56D120679; Fri, 23 Feb 2024 09:58:57 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87bk87i8dc.fsf@localhost> (Ihor Radchenko's message of "Fri, 23 Feb 2024 14:05:19 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> <87y1berrh6.fsf@localhost> <87bk87i8dc.fsf@localhost> Date: Fri, 23 Feb 2024 09:58:55 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.085 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> How 'bout the patch below? >> ... >> +The precise behavior when the object does not actually match the pattern >> +depends on the types, although the body will not be silently skipped: ^^^^^ pattern >> +either an error is signaled or the body is run with some of the >> +variables bound to arbitrary values like @code{nil}. >> +For example, the above pattern will result in @var{x} and @var{y} >> +being extracted with operations like @code{car} or @code{nth}, so they >> +will get value @code{nil} when @var{my-list} is too short. In contrast, >> +with a pattern like @code{`[add ,x ,y]}, those same variables would >> +be extracted using @code{aref} which would signal an error if >> +@var{my-list} is not an array or is too short. > > This is confusing. In particular, "for example" implies that other > situations are possible. It is unclear how the reader will know when > "variables bound to arbitrary values" happen, when variables are bound > to nil, and when an error is signaled. This part of the doc is generic, so it can't guarantee anything: the behavior depends on the actual pattern and the way that pattern is defined. In order to intuit what will happen, the reader needs to guess which primitives are used to extract the info from value (e.g. `car/cdr/nth` for cons cells, `aref` for arrays, ...). > I would re-structure the paragraph, explicitly listing the possible > outcomes when the PATTERN does not match VALUE and stating that any > other non-matching PATTERN will lead to undefined outcome. Could you try to do that? [ I've found back-and-forth modifications of docs give better results than single-sided writing. ] > Also, with the current behavior of `pcase-let', it appears to be > impossible to distinguish between too short list (1 2 3) and > (1 2 3 nil nil) when assigning destructuring pattern. Destructuring by definition can't do "distinguish", so that's not a big surprise =F0=9F=99=82 But of course, this isn't really true, you can do: (pcase-let ((`(,x ,y ,z . ,tail) FOO)) (if (equal tail '(nil nil)) ... ...)) or you can get hairy and do things like: (pcase-let (((or `(,x ,y ,z ,a ,_) (and `(,x ,y ,z) (let a 'shortorlonglist))) FOO)) (if (eq a 'shortorlonglist) ... ...)) but that kind if Pcase pattern, while possible, is rarely worth the trouble. Stefan From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 24 08:40:18 2024 Received: (at 68509) by debbugs.gnu.org; 24 Feb 2024 13:40:18 +0000 Received: from localhost ([127.0.0.1]:57020 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdsGG-0007gv-6C for submit@debbugs.gnu.org; Sat, 24 Feb 2024 08:40:18 -0500 Received: from mout01.posteo.de ([185.67.36.65]:56527) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rds24-00073I-Fh for 68509@debbugs.gnu.org; Sat, 24 Feb 2024 08:25:38 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id CE1A5240027 for <68509@debbugs.gnu.org>; Sat, 24 Feb 2024 14:25:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708781105; bh=EjGEgGzp0SmOVry9FxH3DsmTRlnGqILeTkIAlRU0VAM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=gqo+sqrzDQPphfn3SMXZm2ZcoHNDFqgy3d9BCaAdQNjAt7F8bvr2k7XTQoOMOjwDK ddVtUGdEZsIR9f7YWQQ0Kg8+uLdUOU/OTqt+pnMZGy5zdZgAjwO4+QusOOdRy9xaBc XJzKvoJ7DQDKgHb19baJj7rCwPQE6lwCS7zbqplzk3/oe+3XBF36kCOTaH+LPSBP1b YtBo/o5hVQQS0XPV3R5vlZGDYqEDtPKEyPnFAUM+JGGHaKyx4xLk/bSbtOlAgORxa1 iht1Fx04RdqB1pX/JssVpl0W/OKPzbt6HC7PvjU8bVxJGyrNLQl7463CIr3MSvz03R fz67ixkxaUkKg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Thng45VX5z9rxB; Sat, 24 Feb 2024 14:25:04 +0100 (CET) From: Ihor Radchenko To: Stefan Monnier Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> <87y1berrh6.fsf@localhost> <87bk87i8dc.fsf@localhost> Date: Sat, 24 Feb 2024 13:28:50 +0000 Message-ID: <87sf1ivvn1.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Stefan Monnier writes: >>> +For example, the above pattern will result in... >> >> This is confusing. In particular, "for example" implies that other >> situations are possible. It is unclear how the reader will know when >> "variables bound to arbitrary values" happen, when variables are bound >> to nil, and when an error is signaled. > > This part of the doc is generic, so it can't guarantee anything: the > behavior depends on the actual pattern and the way that pattern is defined. > In order to intuit what will happen, the reader needs to guess which > primitives are used to extract the info from value (e.g. `car/cdr/nth` > for cons cells, `aref` for arrays, ...). I do not think that "guess" is what we should ever put into docs. Because implementation details may change and any kind of guess may then go wrong. >> I would re-structure the paragraph, explicitly listing the possible >> outcomes when the PATTERN does not match VALUE and stating that any >> other non-matching PATTERN will lead to undefined outcome. > > Could you try to do that? > [ I've found back-and-forth modifications of docs give better results > than single-sided writing. ] I could, but I am not sure which non-matching outcomes we should document and which we want to leave undefined. I still don't have a clear picture about the differences between normal pcase and destructuring pcase. Especially for non-trivial patterns. For example, (pcase-let (((and `(,a ,b ,c) (guard (eq a 'foo))) '(bar a))) (list a b c)) ; =>'(bar a nil) is extremely confusing. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 24 09:58:28 2024 Received: (at 68509) by debbugs.gnu.org; 24 Feb 2024 14:58:29 +0000 Received: from localhost ([127.0.0.1]:35744 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdtTw-0003KW-JD for submit@debbugs.gnu.org; Sat, 24 Feb 2024 09:58:28 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:35433) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdtTv-0003KE-7B for 68509@debbugs.gnu.org; Sat, 24 Feb 2024 09:58:27 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5AB34441D31; Sat, 24 Feb 2024 09:57:57 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1708786676; bh=WPgaCynTCYqyzWg7mLRGuKp+9HGzLZLos3MQR6Ae4wQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=NfL3tF0Qedekb3xwfsftNJjRlczzQ/Q3QkTevaUCKG7kyO5FVDMCOe1jT2ac2KVtt 5n3sUkwjXBTb8D5Wje95ZRiu9jlShtCcxrK3k4PFsl0q4/0CMIIBJ48Nl0Ob3JSzcz RcKQGqp7mxEc6jEo2mdbcmucPGWXrnh9b2z8DjebKHQT7cbYTdZ3RhtDls9siPfIo8 HjmNrCKs4Z9I5vc/oJLRIkq4/u/lfyWeaZ5g7+pPHfFDsuXjRmq/IRbsFGaPY1/frB JLew/0V/FekHVJsGh6vAt7s+fKA/JbSy10lWfPQkSz9kkUWkWZcrPxNlYxYV4iRwgs 6jZOiBP+1KhVg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 07228441CEF; Sat, 24 Feb 2024 09:57:56 -0500 (EST) Received: from pastel (unknown [45.72.205.238]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D1B121205FB; Sat, 24 Feb 2024 09:57:55 -0500 (EST) From: Stefan Monnier To: Ihor Radchenko Subject: Re: bug#68509: 30.0.50; pcase-dolist matches backquote pattern incorrectly In-Reply-To: <87sf1ivvn1.fsf@localhost> (Ihor Radchenko's message of "Sat, 24 Feb 2024 13:28:50 +0000") Message-ID: References: <87a5p5l3jm.fsf@localhost> <9bc2bd05-5fdb-9d5a-3d98-c344c7275027@gmail.com> <87sf2xjezi.fsf@localhost> <871q98hiqa.fsf@localhost> <8734to8gov.fsf@localhost> <87o7cbz21n.fsf@localhost> <87jzmzyxlv.fsf@localhost> <87y1berrh6.fsf@localhost> <87bk87i8dc.fsf@localhost> <87sf1ivvn1.fsf@localhost> Date: Sat, 24 Feb 2024 09:57:54 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.005 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 68509 Cc: Jim Porter , 68509@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> Could you try to do that? >> [ I've found back-and-forth modifications of docs give better results >> than single-sided writing. ] > > I could, but I am not sure which non-matching outcomes we should > document and which we want to leave undefined. Try your best. Then I'll try to improve it, then you'll try to improve it... > I still don't have a clear picture about the differences between normal > pcase and destructuring pcase. The best way to clarify it is by writing what you think happens. Don't worry about the risk that what you write is "wrong", because that's the part I can easily catch and fix. Stefan