From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Okamsn via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67611: [PATCH] Add a Pcase pattern `cl-lambda` equivalent to `cl-destructuring-bind` Date: Tue, 05 Dec 2023 02:42:12 +0000 Message-ID: <56ebae03-a94d-4379-bd08-66bde2311bb7@protonmail.com> References: <277dd49a-e96d-4faf-a22e-aca952354a37@protonmail.com> Reply-To: Okamsn Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5137"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67611@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 05 03:43:22 2023 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 1rALP7-0001Ak-SW for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 05 Dec 2023 03:43:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rALOg-0008Ge-3s; Mon, 04 Dec 2023 21:42:54 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rALOe-0008GS-M7 for bug-gnu-emacs@gnu.org; Mon, 04 Dec 2023 21:42:52 -0500 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 1rALOe-0006mp-EM for bug-gnu-emacs@gnu.org; Mon, 04 Dec 2023 21:42:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rALOo-0006FF-4U for bug-gnu-emacs@gnu.org; Mon, 04 Dec 2023 21:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Okamsn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Dec 2023 02:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67611 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170174418123998 (code B ref -1); Tue, 05 Dec 2023 02:43:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Dec 2023 02:43:01 +0000 Original-Received: from localhost ([127.0.0.1]:36213 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rALOm-0006F0-Ns for submit@debbugs.gnu.org; Mon, 04 Dec 2023 21:43:01 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:40110) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rALOj-0006Em-Uf for submit@debbugs.gnu.org; Mon, 04 Dec 2023 21:42:58 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rALOT-0008EH-6Z for bug-gnu-emacs@gnu.org; Mon, 04 Dec 2023 21:42:41 -0500 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rALOM-0006gD-Uo for bug-gnu-emacs@gnu.org; Mon, 04 Dec 2023 21:42:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1701744149; x=1702003349; bh=gs/ATLQ8tv1eVHz4HuKRd34Z2G3cyVIyttqHM5wYIV4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=FWdkNq960pHEyQf5Rv0yPyTUCTANHQ2heAWJJbiyS6OGnbBbSxt7kRxcnqkDNDJfV zUpGCpasRfoOsT5iWYBY6VrxN4EAhBar0q9haZN+0SOmQCnDXSDK9Czg9My7GyqD7W +VvWBlJG3hiFXdPF+7oARws9fmAxfLFBauP2M4PHVfTH6IxSl2kMzD7kbmRhPfXrYr DGjDHMJGTXceo7X+kHetuXoyLUVidfpFIxZwC91NMQe16fp3Y9TOWObKaJS9rccSXE 1aWCBVJHFrFFAIAnOC+O/+Z3wMXmrjD9HKIJ60TgsOUn3gRMqdUfNawhS6RxpCnnSz mYEn9nAhv85+g== In-Reply-To: Feedback-ID: 25935600:user:proton Received-SPF: pass client-ip=185.70.43.16; envelope-from=okamsn@protonmail.com; helo=mail-4316.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275547 Archived-At: Stefan Monnier wrote: >> The attached patch adds the pattern `cl-lambda` for Pcase, which works >> like `cl-destructuring-bind`. There are two differences with the lambda >> lists: >=20 > Hmm... I'm not sure mixing the CL destructuring patterns with the Pcase > patterns (both of which are rather featureful and complex) will help > their popularity. >=20 > Beside that problem (which means I'm not very favorable to the > addition), the name should be changed because "lambda" is misleading. > It suggests this has to do with a function (I had to read the code to > understand what this is doing). I agree that the name is not ideal. When I searched for what the=20 destructuring pattern was called, the website Common Lisp HyperSpec=20 called it a "destructuring lambda list"=20 (https://www.lispworks.com/documentation/HyperSpec/Body/03_de.htm). I=20 would have suggested "cl", as it is the kind of destructuring used by=20 the macros of cl-lib, but I thought that would not work well with the=20 existence of the "cl-type" pattern. I also thought about something like=20 "cl-arglist", if that is better. >> The pattern is useful when one wants to combine the features of `pcase` >> and `cl-destructuring-bind`, such combining the optional values with the >> `pred` or `guard` patterns. >=20 > Do you have examples uses? Not of that idea, no. I maintain a library that implements a=20 destructuring pattern like cl-lib=20 (https://github.com/okamsn/loopy/blob/master/doc/loopy-doc.org#basic-destru= cturing)=20 and I have been thinking about how I could use Pcase to simplify the=20 implementation of the destructuring and to stop using a re-invented=20 wheel. While doing that, it occurred to me that cl-lib itself might be a=20 better place for such a Pcase pattern. To be clear, the patch only=20 implements the cl-lib destructuring, not the other destructuring ideas=20 from my library. For me, I am interested in using such a destructuring pattern with=20 `pcase-let` and `pcase-setq`, but not so much with `pcase` itself. > Maybe we could introduce a different Pcase pattern which covers those > needs but stays closer to the Pcase pattern syntax? As far as I understand Pcase, one thing that I think cl-lib does better=20 is specifying default values for multiple optional variables. For=20 example, for `(a &optional (b 2) (c 3))` in Pcase, I would write (or `(,a ,b ,c) (and `(,a ,b) (let c 3)) (and `(,a) (let c 3) (let b 2))) or `(,a . ,(or `(,b . ,(or `(,c) (let c 3))) (and (let b 2) (let c 3)))) in which there is repetition in the default values. Is there a better=20 way to specify default values for optional elements? Thank you.