From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#47261: Destructuring with Pcase without assigning values Date: Fri, 19 Mar 2021 17:45:00 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29861"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 47261@debbugs.gnu.org To: Okam Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 19 22:47:20 2021 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 1lNMxk-0007fU-5O for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 19 Mar 2021 22:47:20 +0100 Original-Received: from localhost ([::1]:34346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNMxi-00048X-Sl for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 19 Mar 2021 17:47:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNMxT-00047A-1d for bug-gnu-emacs@gnu.org; Fri, 19 Mar 2021 17:47:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39598) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lNMxS-0004r1-5j for bug-gnu-emacs@gnu.org; Fri, 19 Mar 2021 17:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lNMxS-00028y-2u for bug-gnu-emacs@gnu.org; Fri, 19 Mar 2021 17:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Mar 2021 21:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47261 X-GNU-PR-Package: emacs Original-Received: via spool by 47261-submit@debbugs.gnu.org id=B47261.16161904068215 (code B ref 47261); Fri, 19 Mar 2021 21:47:02 +0000 Original-Received: (at 47261) by debbugs.gnu.org; 19 Mar 2021 21:46:46 +0000 Original-Received: from localhost ([127.0.0.1]:51144 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNMxB-00028R-Mi for submit@debbugs.gnu.org; Fri, 19 Mar 2021 17:46:45 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:47275) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lNMx9-00028C-7E for 47261@debbugs.gnu.org; Fri, 19 Mar 2021 17:46:45 -0400 Original-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) Original-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== Original-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) In-Reply-To: (Okam's message of "Fri, 19 Mar 2021 13:47:29 +0000") 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" Xref: news.gmane.io gmane.emacs.bugs:202713 Archived-At: > 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