GNU bug report logs - #47261
Destructuring with Pcase without assigning values

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: wishlist; Reported by: Okam <okamsn@HIDDEN>; Done: Lars Ingebrigtsen <larsi@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug closed, send any further explanations to 47261 <at> debbugs.gnu.org and Okam <okamsn@HIDDEN> Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 47261 <at> debbugs.gnu.org:


Received: (at 47261) by debbugs.gnu.org; 24 Jun 2022 18:36:45 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jun 24 14:36:45 2022
Received: from localhost ([127.0.0.1]:43522 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1o4oAQ-0000B7-BU
	for submit <at> debbugs.gnu.org; Fri, 24 Jun 2022 14:36:45 -0400
Received: from quimby.gnus.org ([95.216.78.240]:35394)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1o4oAO-0000As-Cy
 for 47261 <at> debbugs.gnu.org; Fri, 24 Jun 2022 14:36:28 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=QTDriXT/0hvz35YPCR9TYQrV9lm7FXJZQMaiF2kIdkA=; b=jqTfId35Z42e2qIBhcNSH9+4yj
 /MnIHrsY127xQBr0FgfF7BplX9JZt66WXFARl6Gi8EC7BdlN4O2/p7zdwcMjWhanhhW2BBsmeaFab
 DPqpRXhkHEDsNfMSBDyXl8dz+l4Z3acuH/Y3Skkva8ZIYhSprjeL1JR3ptZ4qM+Us0bk=;
Received: from [84.212.220.105] (helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1o4oAD-00042h-AV; Fri, 24 Jun 2022 20:36:20 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#47261: Destructuring with Pcase without assigning values
References: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
 <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
X-Now-Playing: Rocketnumbernine's _Meyouweyou_: "Lope"
Date: Fri, 24 Jun 2022 20:36:16 +0200
In-Reply-To: <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN> (Stefan Monnier's message
 of "Fri, 19 Mar 2021 17:45:00 -0400")
Message-ID: <87r13dnc2n.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview: Stefan Monnier <monnier@HIDDEN> writes: > I
 massaged
 the code so that it now exports the following function: > > (defun
 pcase-compile-patterns
 (exp cases) > "Compile the set of patterns in CASES. 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 47261
Cc: Okam <okamsn@HIDDEN>, 47261 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Stefan Monnier <monnier@HIDDEN> writes:

> I massaged the code so that it now exports the following function:
>
>     (defun pcase-compile-patterns (exp cases)
>       "Compile the set of patterns in CASES.

Skimming this thread, it seems like this fixed the request, so I'm
closing this bug report.  (The discussion then went on to discuss some
things related to this feature, but if I understood correctly, Earl
adjusted his code to fit it.)  If I misunderstood, please respond to the
debbugs address and we'll reopen.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.

Message received at 47261 <at> debbugs.gnu.org:


Received: (at 47261) by debbugs.gnu.org; 19 Apr 2021 22:31:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 19 18:31:46 2021
Received: from localhost ([127.0.0.1]:52305 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lYcQg-0001R8-BT
	for submit <at> debbugs.gnu.org; Mon, 19 Apr 2021 18:31:45 -0400
Received: from mail-40134.protonmail.ch ([185.70.40.134]:60637)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <earl.hyatt@HIDDEN>) id 1lYc2n-0000qc-Jm
 for 47261 <at> debbugs.gnu.org; Mon, 19 Apr 2021 18:07:05 -0400
Date: Mon, 19 Apr 2021 22:06:51 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail; t=1618870015;
 bh=BeiVX9ihKl3r3FJ+mCskx5Tam3YjxPHhHorWTRrismg=;
 h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From;
 b=yPL8gJaKkkyId5SXh83MMlyx6xLP01TfBuvECjHGFXoS1TEDGCzl7NFgPKu8MbKcV
 AZo5az143sTNbbe7UIb6EhKzqz3Z9H9FL2F2MtGNtyDWUmfAAFPqzQ9H2GmYesqgEo
 ghspPns9rsg7qT2TjOtbgvVJ5gX4LDyPdttAM1jA=
To: 47261 <at> debbugs.gnu.org
From: Earl Hyatt <earl.hyatt@HIDDEN>
Subject: Fwd: bug#47261: Destructuring with Pcase without assigning values
Message-ID: <42f78acc-b2f3-9bfd-8891-d316b7a95e1c@HIDDEN>
In-Reply-To: <1dacded9-3e40-bc02-56c7-a157d739ffb7@HIDDEN>
References: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
 <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
 <08c47ffc-58a3-d4f9-eae1-61a672d45b44@HIDDEN>
 <jwvbladd2cb.fsf-monnier+emacs@HIDDEN>
 <1dacded9-3e40-bc02-56c7-a157d739ffb7@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no
 autolearn=disabled version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 mailout.protonmail.ch
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47261
X-Mailman-Approved-At: Mon, 19 Apr 2021 18:31:41 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Earl Hyatt <earl.hyatt@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)


For the record, I am forwarding this reply to the bug tracker. I forgot
to send the original message to the tracker.

-------- Forwarded Message --------
Subject: Re: bug#47261: Destructuring with Pcase without assigning values
Date: Sat, 17 Apr 2021 18:50:10 -0400
From: Okam <okamsn@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>

On 4/16/21 11:22 PM, Stefan Monnier wrote:
>
>>> The `pcase` macro itself uses this function, so it should hopefully be
>>> "good enough", but let me know if it's causing you trouble.
>> This seems to work well for my use case. Thank you for making this chang=
e.
>
> You're welcome.  It was actually a good change for the code's
> readability as well.
>
>> Are the variables always given in the order that they appear in the
>> pattern?
>
> I don't know.  Why? >
>> If not, is finding elements of the form "(\, SYMBOL)" enough to
>> identify variables in a Pcase pattern?
>
> No.  , is not even one of the core pcase patterns, it's only something
> used within the ` pattern (which is not a core pattern either; it is
> defined via `pcase-defmacro`).
>
>
>          Stefan
>

In the `cl-loop`-like macro that I am writing, things are currently set
up so that variables being assigned values in accumulation clauses can
be automatically used as the return value of the macro.

      ;; =3D> ((1 3 5) (2 4 6))
      (loopy (flag pcase)
             (list i '((1 2) (3 4) (5 6)))
             (collect `(,a ,b) i))

This behavior requires finding the variables in the correct order.

The getting of the variables used ("a" and "b" above) can be done when
using the new `pcase-compile-pattern`, if the variables are fed to the
CODEGEN argument in the order that they are written, or I can try to
find them manually, if possible.

If neither are possible, then I will just remove this behavior.

Thank you.





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.

Message received at 47261 <at> debbugs.gnu.org:


Received: (at 47261) by debbugs.gnu.org; 19 Apr 2021 22:10:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 19 18:10:42 2021
Received: from localhost ([127.0.0.1]:52295 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lYc6M-0000w7-2P
	for submit <at> debbugs.gnu.org; Mon, 19 Apr 2021 18:10:42 -0400
Received: from mail-40133.protonmail.ch ([185.70.40.133]:29955)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <okamsn@HIDDEN>) id 1lYc6J-0000vs-Pd
 for 47261 <at> debbugs.gnu.org; Mon, 19 Apr 2021 18:10:40 -0400
Date: Mon, 19 Apr 2021 22:10:28 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail; t=1618870233;
 bh=5JOSoiPyztfACKFQrjhB9/jLsIzgKWvYQPQkhg/Qqcc=;
 h=Date:To:From:Reply-To:Subject:In-Reply-To:References:From;
 b=l1rbzJTyQMapBMO3svN5c021M1ayOk+B1LaULA9VktOmVDp8OhNi+Yen4i9BYLEX+
 W45eT60ymPulBk7Y6nVb0a8ow6dJVvSguR7RJtbwy7N+tu42V/HS0BgBR/QoFU6iJ8
 C7Miijbz6xvhNiUzb3hNAiL2YPr0fAGq/XHPu5d8=
To: 47261 <at> debbugs.gnu.org
From: Okam <okamsn@HIDDEN>
Subject: Fwd: bug#47261: Destructuring with Pcase without assigning values
Message-ID: <d52d950c-d003-6b00-d4ed-198afcec06a5@HIDDEN>
In-Reply-To: <4925d1a5-4669-8290-e534-1662f13ca183@HIDDEN>
References: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
 <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
 <08c47ffc-58a3-d4f9-eae1-61a672d45b44@HIDDEN>
 <jwvbladd2cb.fsf-monnier+emacs@HIDDEN>
 <1dacded9-3e40-bc02-56c7-a157d739ffb7@HIDDEN>
 <jwveef84hcl.fsf-monnier+emacs@HIDDEN>
 <4925d1a5-4669-8290-e534-1662f13ca183@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no
 autolearn=disabled version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 mailout.protonmail.ch
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47261
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Okam <okamsn@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

For the record, I am forwarding this reply to the bug tracker. I forgot
to send the original message to the tracker.


-------- Forwarded Message --------
Subject: Re: bug#47261: Destructuring with Pcase without assigning values
Date: Sun, 18 Apr 2021 15:15:00 -0400
From: Okam <okamsn@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>

On 4/17/21 7:37 PM, Stefan Monnier wrote:
>
>> In the `cl-loop`-like macro that I am writing, things are currently set
>> up so that variables being assigned values in accumulation clauses can
>> be automatically used as the return value of the macro.
>>
>>       ;; =3D> ((1 3 5) (2 4 6))
>>       (loopy (flag pcase)
>>              (list i '((1 2) (3 4) (5 6)))
>>              (collect `(,a ,b) i))
>>
>> This behavior requires finding the variables in the correct order.
>>
>> The getting of the variables used ("a" and "b" above) can be done when
>> using the new `pcase-compile-pattern`, if the variables are fed to the
>> CODEGEN argument in the order that they are written, or I can try to
>> find them manually, if possible.
>
> I still don't understand.  AFAICT what the (collect `(,a ,b) i) above is
> expected to do is something more or less equivalent to:
>
>      (push (car i) a)
>      (push (cadr i) b)
>
> right?
>
> So a CODEGEN which does
>
>     (lambda (varvals _count &rest _)
>       (mapcar (lambda (varval)
>                 `(push ,(cadr varval) ,(car varval)))
>               varvals))
>
> should do the trick, regardless of the order in which the vars
> are passed.
>
> I think I'm still missing something in your explanation.
>
>
>          Stefan
>

What I mean to say is that, if possible, I would like to add the
variables in the pattern to a list of values to return.  This requires
identifying the symbols which represent the variables.

Using CODEGEN works for setting the values, yes, and is not sensitive to
the order in which it receives variables. However, I am currently using
the CODEGEN step to add the variables to a list of returned values,
since CODEGEN is already being given the symbol for each variable.

I am trying to have it so that these variables are listed in the return
value in the same order that they are listed in the pattern.

For example, this

      ;; =3D> (4 6)
      (loopy (flag pcase)
             (list i '([1 2] [3 4]))
             (sum `[,sum1 ,sum2] i))

currently expands to

      (let ((sum2 0)
            (sum1 0))
        (let* ((list-108 '([1 2] [3 4]))
               (i nil))
          (cl-block nil
            (while (consp list-108)
              (setq i (car list-108))
              (if (vectorp i)
                  (let* ((x109 (length i)))
                    (if (eql x109 2)
                        (let* ((x110 (pcase--flip aref 0 i))
                               (x111 (pcase--flip aref 1 i)))
                          (progn
                            (setq sum2 (+ x111 sum2))
                            (setq sum1 (+ x110 sum1)))))))
              (setq list-108 (cdr list-108)))
            (list sum1 sum2))))

where `sum1` and `sum2` are in the same order that they appear in the
pattern.  This works with what I have tested, but I am unsure of whether
it is dependable.

So, I am asking whether the variables passed to CODEGEN can be relied on
to be in a particular order for destructuring patterns, or whether there
is a good way to find the variables and their order manually.

For example, for `seq-let`-like destructuring, my experience is that the
variables are given in the reverse order and that variables can be
identified as symbols that are not `&rest`.





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.

Message received at 47261 <at> debbugs.gnu.org:


Received: (at 47261) by debbugs.gnu.org; 17 Apr 2021 03:23:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 16 23:23:21 2021
Received: from localhost ([127.0.0.1]:42014 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lXbYD-0007aH-Nd
	for submit <at> debbugs.gnu.org; Fri, 16 Apr 2021 23:23:21 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:15211)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1lXbY7-0007Zz-NS
 for 47261 <at> debbugs.gnu.org; Fri, 16 Apr 2021 23:23:16 -0400
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 3C3BF80931;
 Fri, 16 Apr 2021 23:23:06 -0400 (EDT)
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4A029801F1;
 Fri, 16 Apr 2021 23:23:04 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1618629784;
 bh=XMNJcte6IC57C3ttyGSutfZzgyft6xj6i9naEH9YCIc=;
 h=From:To:Cc:Subject:References:Date:In-Reply-To:From;
 b=WqG9QdrSp5k+LaitwTab7UzY4yVVJO+tWgibphxBn4frwzYFSfINwaZv9HLhuph3d
 x3EKl8PPF9rgWQYitCYEumKSXaYbNUmYGAnGqVrQm2Kc+rD9Kvi9Z7QikDyqFHgcUD
 UZXK2qVxMCLkZppHGDLJP9wevUecuHALpx2kfUrg3kk5Y+ly3zBdmm8HAt0JD6k5sN
 rYq3bRuSen/W6ADa8VtukPHIGNLiMT/sRIrkXi/cvkkvB2B/cBNdRgVmtCcSmHwaZ0
 nA/ALdNi7Ds7zpR9AiQZXnCEF/FVDIgy4kRweJ2PhkR/+N5j/X1zatyJS6Yj3B2A7m
 EbwyteuNRbCXw==
Received: from alfajor (104-222-126-84.cpe.teksavvy.com [104.222.126.84])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 06960120329;
 Fri, 16 Apr 2021 23:23:03 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Okam <okamsn@HIDDEN>
Subject: Re: bug#47261: Destructuring with Pcase without assigning values
Message-ID: <jwvbladd2cb.fsf-monnier+emacs@HIDDEN>
References: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
 <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
 <08c47ffc-58a3-d4f9-eae1-61a672d45b44@HIDDEN>
Date: Fri, 16 Apr 2021 23:22:57 -0400
In-Reply-To: <08c47ffc-58a3-d4f9-eae1-61a672d45b44@HIDDEN> (Okam's
 message of "Sat, 17 Apr 2021 01:24:11 +0000")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
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.056 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
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 47261
Cc: 47261 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> The `pcase` macro itself uses this function, so it should hopefully be
>> "good enough", but let me know if it's causing you trouble.
> This seems to work well for my use case. Thank you for making this change.

You're welcome.  It was actually a good change for the code's
readability as well.

> Are the variables always given in the order that they appear in the
> pattern?

I don't know.  Why?

> If not, is finding elements of the form "(\, SYMBOL)" enough to
> identify variables in a Pcase pattern?

No.  , is not even one of the core pcase patterns, it's only something
used within the ` pattern (which is not a core pattern either; it is
defined via `pcase-defmacro`).


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.

Message received at 47261 <at> debbugs.gnu.org:


Received: (at 47261) by debbugs.gnu.org; 17 Apr 2021 01:24:31 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Apr 16 21:24:31 2021
Received: from localhost ([127.0.0.1]:41992 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lXZhD-0004dY-53
	for submit <at> debbugs.gnu.org; Fri, 16 Apr 2021 21:24:31 -0400
Received: from mail2.protonmail.ch ([185.70.40.22]:15340)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <okamsn@HIDDEN>) id 1lXZh8-0004dI-Hk
 for 47261 <at> debbugs.gnu.org; Fri, 16 Apr 2021 21:24:26 -0400
Date: Sat, 17 Apr 2021 01:24:11 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail; t=1618622655;
 bh=yyEAiozRx3AzlgRwqKDSaYa6XDlOp9OXlnpbONa5DxE=;
 h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From;
 b=uXHAsqbsNk0xjNf4/+4ztWUQA3taGcyrvwBmZEU4Pebz9dC215V148/CsPPWEurgA
 rzsBcDCGH1MGHAMBRBcpdOgFxnT712ZB/9Gt+Wrp7F9sIL0iVDu+ar4hQ8QM3Agp5y
 RyHAJ4WNNwTpAZ3UtD1tns243whr6lAkfw+ZPkYc=
To: Stefan Monnier <monnier@HIDDEN>
From: Okam <okamsn@HIDDEN>
Subject: Re: bug#47261: Destructuring with Pcase without assigning values
Message-ID: <08c47ffc-58a3-d4f9-eae1-61a672d45b44@HIDDEN>
In-Reply-To: <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
References: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
 <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no
 autolearn=disabled version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 mailout.protonmail.ch
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47261
Cc: 47261 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Okam <okamsn@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

On 3/19/21 5:45 PM, Stefan Monnier wrote:
> I massaged the code so that it now exports the following function:
>
>      (defun pcase-compile-patterns (exp cases)
>        "Compile the set of patterns in CASES.
>      EXP is the expression that will be matched against the patterns.
>      CASES is a list of elements (PAT . CODEGEN)
>      where CODEGEN is a function that returns the code to use when
>      PAT matches.  That code has to be in the form of a cons cell.
>
>      CODEGEN will be called with at least 2 arguments, VARVALS and COUNT.
>      VARVALS is a list of elements of the form (VAR VAL . RESERVED) where=
 VAR
>      is a variable bound by the pattern and VAL is a duplicable expressio=
n
>      that returns the value this variable should be bound to.
>      If the pattern PAT uses `or', CODEGEN may be called multiple times,
>      in which case it may want to generate the code differently to avoid
>      a potential code explosion.  For this reason the COUNT argument indi=
cates
>      how many time this CODEGEN is called."
>
> The `pcase` macro itself uses this function, so it should hopefully be
> "good enough", but let me know if it's causing you trouble.
>
>
>          Stefan
>

This seems to work well for my use case. Thank you for making this change.

Are the variables always given in the order that they appear in the
pattern? If not, is finding elements of the form "(\, SYMBOL)" enough to
identify variables in a Pcase pattern?





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.

Message received at 47261 <at> debbugs.gnu.org:


Received: (at 47261) by debbugs.gnu.org; 19 Mar 2021 21:46:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 19 17:46:45 2021
Received: from localhost ([127.0.0.1]:51144 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lNMxB-00028R-Mi
	for submit <at> debbugs.gnu.org; Fri, 19 Mar 2021 17:46:45 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47275)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1lNMx9-00028C-7E
 for 47261 <at> debbugs.gnu.org; Fri, 19 Mar 2021 17:46:45 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B345D10023D;
 Fri, 19 Mar 2021 17:46:37 -0400 (EDT)
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 34370100225;
 Fri, 19 Mar 2021 17:46:36 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1616190396;
 bh=FlTUENx/vNRhFzucZIodnPIhwMyH9igvjOQVPJRsR68=;
 h=From:To:Cc:Subject:References:Date:In-Reply-To:From;
 b=ir6to1KI1VPfuwHbK0rssLODvKvdimHkbYFIYZ1d/xqlGbMwjmPTklDdp0t7ovm7R
 r73qaFbg2v0qFZ7a2Cy3yAvRcXl1RgAPSUIVRW/Bj8cmd4Xf2SE+dGZgE3DlBXCByg
 XiV2G6vMXuLq0r4uiqbnl6cOoYLwg+Qu2G+IhtowQ3/Mnv9xoQcWOmt/zj6u71I+nY
 3r3WBlTe4AR/cT2fW1t0apJi/llGFMT4oPeKCfMWiBunRJZyUtSG9obzbjeuiGJx5S
 iHhfJabhsQEqPw4zhzWbwn6OEMK8DwvV7mrT8fJjZZShNGWMiLWOAjY1g/5pMm72fF
 vY6/VZD013iIw==
Received: from alfajor (unknown [216.154.43.249])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 06659120263;
 Fri, 19 Mar 2021 17:46:35 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Okam <okamsn@HIDDEN>
Subject: Re: bug#47261: Destructuring with Pcase without assigning values
Message-ID: <jwvmtuy6crx.fsf-monnier+emacs@HIDDEN>
References: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
Date: Fri, 19 Mar 2021 17:45:00 -0400
In-Reply-To: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN> (Okam's
 message of "Fri, 19 Mar 2021 13:47:29 +0000")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
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.099 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
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 47261
Cc: 47261 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> For a Pcase pattern, it would be convenient to have Pcase destructure
> the pattern and have a way to see what values Pcase would like to assign
> to variables within the pattern.
>
> This would allow one to know the variables found in the pattern and to
> manipulate the values that Pcase would like to assign, instead of just
> letting `pcase` assign them.

I massaged the code so that it now exports the following function:

    (defun pcase-compile-patterns (exp cases)
      "Compile the set of patterns in CASES.
    EXP is the expression that will be matched against the patterns.
    CASES is a list of elements (PAT . CODEGEN)
    where CODEGEN is a function that returns the code to use when
    PAT matches.  That code has to be in the form of a cons cell.
    
    CODEGEN will be called with at least 2 arguments, VARVALS and COUNT.
    VARVALS is a list of elements of the form (VAR VAL . RESERVED) where VAR
    is a variable bound by the pattern and VAL is a duplicable expression
    that returns the value this variable should be bound to.
    If the pattern PAT uses `or', CODEGEN may be called multiple times,
    in which case it may want to generate the code differently to avoid
    a potential code explosion.  For this reason the COUNT argument indicates
    how many time this CODEGEN is called."

The `pcase` macro itself uses this function, so it should hopefully be
"good enough", but let me know if it's causing you trouble.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 19 Mar 2021 13:47:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 19 09:47:53 2021
Received: from localhost ([127.0.0.1]:49094 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lNFTk-0001Yk-Va
	for submit <at> debbugs.gnu.org; Fri, 19 Mar 2021 09:47:53 -0400
Received: from lists.gnu.org ([209.51.188.17]:39754)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <okamsn@HIDDEN>) id 1lNFTh-0001Yb-Dw
 for submit <at> debbugs.gnu.org; Fri, 19 Mar 2021 09:47:51 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:38172)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <okamsn@HIDDEN>)
 id 1lNFTh-0003Ej-0j
 for bug-gnu-emacs@HIDDEN; Fri, 19 Mar 2021 09:47:49 -0400
Received: from mail-40134.protonmail.ch ([185.70.40.134]:31163)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <okamsn@HIDDEN>)
 id 1lNFTb-00079p-J3
 for bug-gnu-emacs@HIDDEN; Fri, 19 Mar 2021 09:47:48 -0400
Date: Fri, 19 Mar 2021 13:47:29 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail; t=1616161654;
 bh=GHIwvHhy9lfE5sUHeTWWPAS/uP9JahkgXQMJkRfOyNM=;
 h=Date:To:From:Reply-To:Subject:From;
 b=XAIiXpwekaep7o+UQt2huiFeMZDB/xJW9Gm2EQKrZ+OeLRv4pJTtJfqhe4E4DrtWc
 eFpkd2oPGCDna+4DrGaOV0LfaH54jQpWE5D4YcMdFsJsjVSmmV9IQDvRV8UFyUEYGJ
 FKN0OmCe0fU2h2EcrK5N+MXzwGn3ws8VsheD6RT0=
To: bug-gnu-emacs@HIDDEN
From: Okam <okamsn@HIDDEN>
Subject: Destructuring with Pcase without assigning values
Message-ID: <cc1975f5-4e2f-2a62-5141-062422a754a2@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no
 autolearn=disabled version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 mailout.protonmail.ch
Received-SPF: pass client-ip=185.70.40.134; envelope-from=okamsn@HIDDEN;
 helo=mail-40134.protonmail.ch
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Reply-To: Okam <okamsn@HIDDEN>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

X-Debbugs-Cc: monnier@HIDDEN

Hello.

For a Pcase pattern, it would be convenient to have Pcase destructure
the pattern and have a way to see what values Pcase would like to assign
to variables within the pattern.

This would allow one to know the variables found in the pattern and to
manipulate the values that Pcase would like to assign, instead of just
letting `pcase` assign them.

This was asked about on the Help mailing list:
https://lists.gnu.org/archive/html/help-gnu-emacs/2021-03/msg00089.html

Thank you.





Acknowledgement sent to Okam <okamsn@HIDDEN>:
New bug report received and forwarded. Copy sent to monnier@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to monnier@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#47261; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 24 Jun 2022 18:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.