From: Okamsn via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 67611@debbugs.gnu.org
Subject: bug#67611: [PATCH] Add a Pcase pattern `cl-lambda` equivalent to `cl-destructuring-bind`
Date: Tue, 05 Dec 2023 02:42:12 +0000 [thread overview]
Message-ID: <56ebae03-a94d-4379-bd08-66bde2311bb7@protonmail.com> (raw)
In-Reply-To: <jwvplzllrrm.fsf-monnier+emacs@gnu.org>
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:
>
> 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.
>
> 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
destructuring pattern was called, the website Common Lisp HyperSpec
called it a "destructuring lambda list"
(https://www.lispworks.com/documentation/HyperSpec/Body/03_de.htm). I
would have suggested "cl", as it is the kind of destructuring used by
the macros of cl-lib, but I thought that would not work well with the
existence of the "cl-type" pattern. I also thought about something like
"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.
>
> Do you have examples uses?
Not of that idea, no. I maintain a library that implements a
destructuring pattern like cl-lib
(https://github.com/okamsn/loopy/blob/master/doc/loopy-doc.org#basic-destructuring)
and I have been thinking about how I could use Pcase to simplify the
implementation of the destructuring and to stop using a re-invented
wheel. While doing that, it occurred to me that cl-lib itself might be a
better place for such a Pcase pattern. To be clear, the patch only
implements the cl-lib destructuring, not the other destructuring ideas
from my library.
For me, I am interested in using such a destructuring pattern with
`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
is specifying default values for multiple optional variables. For
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
way to specify default values for optional elements?
Thank you.
next prev parent reply other threads:[~2023-12-05 2:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-03 20:33 bug#67611: [PATCH] Add a Pcase pattern `cl-lambda` equivalent to `cl-destructuring-bind` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 19:08 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-05 2:42 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-12-05 9:26 ` João Távora
2023-12-05 9:21 ` João Távora
2023-12-25 21:30 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-11 21:12 ` Stefan Kangas
2024-01-11 21:56 ` João Távora
2024-01-11 22:13 ` Stefan Kangas
2024-01-11 22:46 ` João Távora
2024-01-12 0:55 ` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-13 6:38 ` Stefan Kangas
2024-01-12 3:04 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-12 10:46 ` João Távora
2024-01-12 15:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-12 16:56 ` João Távora
2024-01-13 6:58 ` Stefan Kangas
2024-01-14 3:08 ` Richard Stallman
2024-01-14 3:12 ` João Távora
2024-01-17 3:29 ` Richard Stallman
2024-01-17 9:12 ` João Távora
2024-02-08 3:49 ` Richard Stallman
2024-02-08 13:41 ` João Távora
2024-02-11 3:28 ` Richard Stallman
2024-02-12 15:25 ` João Távora
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56ebae03-a94d-4379-bd08-66bde2311bb7@protonmail.com \
--to=bug-gnu-emacs@gnu.org \
--cc=67611@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=okamsn@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).