From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Marco Antoniotti Newsgroups: gmane.emacs.bugs Subject: bug#70597: Problem in pcase-let? Date: Sun, 28 Apr 2024 17:38:30 +0200 Message-ID: References: <662d23bf.050a0220.a4e2f.3f45@mx.google.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000720ee9061729ee1b" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6000"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Bruno Barbier , 70597@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 28 17:40:01 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s16dF-0001Iw-5f for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Apr 2024 17:40:01 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s16cx-0005bT-SX; Sun, 28 Apr 2024 11:39:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s16cx-0005bK-46 for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 11:39:43 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s16cw-0002cf-Sv for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 11:39:42 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s16dG-0000IQ-AA for bug-gnu-emacs@gnu.org; Sun, 28 Apr 2024 11:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marco Antoniotti Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Apr 2024 15:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70597 X-GNU-PR-Package: emacs Original-Received: via spool by 70597-submit@debbugs.gnu.org id=B70597.17143187481122 (code B ref 70597); Sun, 28 Apr 2024 15:40:02 +0000 Original-Received: (at 70597) by debbugs.gnu.org; 28 Apr 2024 15:39:08 +0000 Original-Received: from localhost ([127.0.0.1]:50847 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s16cO-0000I2-Ch for submit@debbugs.gnu.org; Sun, 28 Apr 2024 11:39:08 -0400 Original-Received: from mail-yb1-xb34.google.com ([2607:f8b0:4864:20::b34]:47309) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s16cN-0000Hh-35 for 70597@debbugs.gnu.org; Sun, 28 Apr 2024 11:39:07 -0400 Original-Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-de54cb87998so3974335276.2 for <70597@debbugs.gnu.org>; Sun, 28 Apr 2024 08:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714318722; x=1714923522; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QmaceAQF+6IWu/G3Y8gcQ+5+FRvW7pBcPeip8dY3SBg=; b=ZESKCWFVsZ+8lGs26cZp8unzJjs2tbwBFTG4A0kc2+1CCa8SWvaIr8WAj6YY5J0Hvx ltHLk6yYT3ouiafG+Ss7pIMYLMcorvQA3t+lQY3LbxBK+b+DAf0o4sggDRII6FKoBqLn VC+2JsmKqSkzcP3sdUvKf3H4CE4G1aeCOnAauaii89T5aCnVOqLKB6AKezCI1ipoRQ7O bYP9REdpF+AdtZvdGazJes1PTL3SeiFEaCEeKWERPy9jO5CIa7+glR6Ggb5L5WmjlEij aH87KTwU8W9JmRkya3wcW7Mpxbsnha+pZqnENfYlTUnn9U3oXhuknUcACP+9O+n/guMh nR4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714318722; x=1714923522; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QmaceAQF+6IWu/G3Y8gcQ+5+FRvW7pBcPeip8dY3SBg=; b=hgMWI+1wuDUPBTyWVUfZtKYJ6kYLcVtj7EI4FAVuIUQoEpmTz/TY6t/L1vZXhELIwB eQJMMdr33ee3TEnkaB0eLuTQCa9zRHnMOiM/IZWjkR4rTgTbyaVRUf2mtQD42U8kBn+2 lhJ2KIGJUxRvSGz47M3rQAyCHEm4ZeZTQxElyjoFd2ouTj+oBnfzD1l58h5X6x3YMiJX 9+MXpNgJ8iGtxTu9+42ryb5+/BpKoH2WJ3blBV97GavzfRsardAQUnahKRIAJmDzGsVd FYFUxAigq2WASzY8z8U3E0Ua263HMppVMQRcjvN8cLhqQgF1d9BDFklecUghHl7NSek1 K/7w== X-Forwarded-Encrypted: i=1; AJvYcCU9RslgXMPs2sKkzpsucrraGbbmvkACqnmnt0DiO01bJesklA414Jor1MBJ249nf8FDaeD0pIpRXOrmMGiemk8/snivzEQ= X-Gm-Message-State: AOJu0YzjPg/6zcCplg2hZByJe8201ZA0UY5rbUxILXWuf6HRWRgz6cN3 82Xn8dLCXLJuHraovABwnaruzeJ71BO4a5Fdf21NQ0puRvAKb0pFBEe7t19LouEFPkyhi5Iv5P6 qtEq97CGsQLufK5hPI2kokIF6vaA= X-Google-Smtp-Source: AGHT+IFDCheado547Q/0h7p7Hi65WSQUb2Ec8Xnx7tTrrkP8q9m612GE+QRZHdkLW95aJVndspX8Wus8c2+5YWiNynk= X-Received: by 2002:a25:7447:0:b0:dd1:3421:b3ea with SMTP id p68-20020a257447000000b00dd13421b3eamr9091780ybc.21.1714318721811; Sun, 28 Apr 2024 08:38:41 -0700 (PDT) In-Reply-To: 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:284095 Archived-At: --000000000000720ee9061729ee1b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you all for the replies. Let me just answer the destructuring-bind comment by Stefan (I am answering to his last email). The previous ones are somewhat answered here as well. In some sense, yes. I kind of want destructuring-bind. It is, IMHO, unfortunate that ELisp does not have it and that we don't have cl-destructuring-bind either; lower level beast than matching, but useful. As per the pcase-let, I still think that the name and/or its behavior are confusing because of expectations about how a pattern matcher usually works. Of course you have the problems with "no matching" but that semantics can be dealt with separately, without surprising the user (at least me). And note that this is, IMHO, "surprising". *(pcase-let (`(foo bar ,x) '(bar foo 42)) x)* IMHO, this should either return nil or signal an error. With destructuring-bind* I would write (assuming indifference variables): *(destructuring-bind* (_ _ x) x)* All the best Marco On Sun, Apr 28, 2024 at 5:22=E2=80=AFPM Stefan Monnier wrote: > > Pattern matchers do ... pattern matching. > > `pcase` is a pattern matcher. > `pcase-let` is not: it performs "destructuring bindings". > > If you want to test if a pattern matches, then you want to use `pcase` > or `pcase-exhaustive`, and not `pcase-let`. > > If you want a "one-branch `pcase-exhaustive` with a let-style notation", > we could add such a thing of course, but I'd first like to see some > evidence that it's useful in practice. > > > Stefan > > --=20 Marco Antoniotti Somewhere over the Rainbow --000000000000720ee9061729ee1b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you all for the replies.

Let me just answer the destructuring= -bind comment by Stefan (I am answering to his last email).=C2=A0 Th= e previous ones are somewhat answered here as well.

In some se= nse, yes.=C2=A0 I kind of want destru= cturing-bind.=C2=A0 It is, IMHO, unfortunate that ELisp does not hav= e it and that we don't have cl-de= structuring-bind either; lower level beast than matching, but useful= .

As per the pcase-= let, I still think that the name and/or its behavior are confusing b= ecause of expectations about how a pattern matcher usually works.=C2=A0 Of = course you have the problems with "no matching" but that semantic= s can be dealt with separately, without surprising the user (at least me).= =C2=A0 And note that this is, IMHO, "surprising".

(pcase-let (`(foo bar ,x) '(bar f= oo 42)) x)

IMHO, this should either return= nil or signal an error.=C2=A0= With=C2=A0destructuring-bind*= I would write (assuming indifference variables):

(destructuring-bind* (_ _ x) x)
All the best

Marco

On Sun, Apr 28, 2024 at 5:22=E2=80=AFPM Stefan Monnier <monnier@iro.umontreal.ca> wrote= :
> Pattern m= atchers do ... pattern matching.

`pcase` is a pattern matcher.
`pcase-let` is not: it performs "destructuring bindings".

If you want to test if a pattern matches, then you want to use `pcase`
or `pcase-exhaustive`, and not `pcase-let`.

If you want a "one-branch `pcase-exhaustive` with a let-style notation= ",
we could add such a thing of course, but I'd first like to see some
evidence that it's useful in practice.


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan



--
Marco Antonio= tti
Somewhere over the Rainbow
--000000000000720ee9061729ee1b--