From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: How to extract bindings from `pcase-let*`?
Date: Mon, 15 Mar 2021 22:45:32 -0400 [thread overview]
Message-ID: <jwvim5rrfmo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 3217e2b9-1b58-1984-ba0a-4526e76cfb4d@protonmail.com
> (pcase-let* ((`(let* ,temp-vars (let ,true-vars . ,_))
> (macroexpand `(pcase-let* ((,var ,val)) ,var))))
> (list temp-vars true-vars)))
Indeed it's not reliable: for a case like
(pcase-let (((or `(inorder ,x ,y) `(reverse ,y ,x)) FOO))
(cons x y))
it will generate code comparable to
(if (eq (car FOO) 'inorder)
(cons (nth 1 FOO) (nth 2 FOO))
(cons (nth 2 FOO) (nth 1 FOO))
[ Just obfuscated with gensym'd vars and such ]
And if you replace the trivial (cons x y) with something less trivial it
will turn into something comparable to:
(let ((body (lambda (x y) <something-less-trivial>)))
(if (eq (car FOO) 'inorder)
(funcall body (nth 1 FOO) (nth 2 FOO))
(funcall body (nth 2 FOO) (nth 1 FOO))))
so it's far from clear how to represent this kind of code in the form of
"a list of bindings that can be substituted into forms like `setq` or
`let*`"
OTOH, I think `pcase.el` could offer a function which could take
a "buildbody" function as argument, where that buildbody would receive
something like the list (x y) and would be expected to return the
(lambda (x y) <something-less-trivial>) to use. So you could pass it a "buildbody"
function which takes the list (x y) and returns something like
(lambda (tmp1 tmp2) (setq x tmp1 y tmp2)), which I expect would do more
or less what you want.
> I am doing this to attempt to optionally use Pcase for destructuring in
> a macro that I am writing.
`pcase-let` already does destructuring, so could you explain in a bit
more detail what kind of destructuring you're looking for (and why)?
Stefan
next prev parent reply other threads:[~2021-03-16 2:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 1:43 How to extract bindings from `pcase-let*`? Okam
2021-03-15 15:38 ` Stefan Monnier
2021-03-16 1:50 ` Okam
2021-03-16 2:45 ` Stefan Monnier [this message]
2021-03-17 1:33 ` Okam
2021-03-17 2:59 ` Stefan Monnier
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvim5rrfmo.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.