From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Cc: Nicolas Petton <nicolas@petton.fr>
Subject: Re: [Emacs-diffs] map 988d721: Add a pcase pattern for maps and `map-let' based on it
Date: Tue, 02 Jun 2015 21:06:44 -0400 [thread overview]
Message-ID: <jwvbngx1unb.fsf-monnier+emacsdiffs@gnu.org> (raw)
In-Reply-To: <E1YzsfE-0005vH-4d@vcs.savannah.gnu.org> (Nicolas Petton's message of "Tue, 02 Jun 2015 20:19:56 +0000")
> + "pcase pattern matching map elements.
> +Matches if the object is a map (list, hash-table or array), and
> +binds values from ARGS to the corresponding element of the map.
> +
> +ARGS can be an alist of key/binding pairs of a list of keys."
I think this would benefit from a bit more detail. E.g. you could say
"ARGS is a list of elements of the form (KEY PAT)" or something
like that.
> + (seq-map (lambda (elt)
> + (if (consp elt)
> + `(app (pcase--flip map-elt ',(car elt)) ,(cdr elt))
> + `(app (pcase--flip map-elt ',elt) ,elt)))
> + args))
Hmm... It looks like it's actually elements of the form (KEY . PAT) or
elements of the form SYMBOL which stands for (SYMBOL . SYMBOL).
Some alternatives to consider:
- Use (KEY PAT) instead of (KEY . PAT). This makes the source code
a bit more concise, so I'm in favor of the (KEY PAT) form.
- Use a plist rather than an alist. I like alists better in general, so
I'm fine with this choice.
- let KEY be evaluated rather than having it be quoted. I.e. require
the programmer to write 'a when looking up the key `a'. It costs an
extra quote in some/many cases, but does give you extra power.
Of course, the downside is that it begs the question of what to do
with the SYMBOL case.
FWIW, in dash.el, the `-let' includes a similar destructuring
facility, with patterns of the form:
(&plist key0 a0 ... keyN aN) - bind value mapped by keyK in the
`source` plist to aK. If the
value is not found, aK is nil.
(&alist key0 a0 ... keyN aN) - bind value mapped by keyK in the
`source` alist to aK. If the
value is not found, aK is nil.
(&hash key0 a0 ... keyN aN) - bind value mapped by keyK in the
`source` hash table to aK. If the
value is not found, aK is nil.
where, AFAICT the `key's are expressions which are evaluated before
being passed to the respective lookup function. IOW when you want
a constant key you need to quote it, unless that constant is
self-quoting (e.g. a keyword).
Stefan
next parent reply other threads:[~2015-06-03 1:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20150602201956.22733.21800@vcs.savannah.gnu.org>
[not found] ` <E1YzsfE-0005vH-4d@vcs.savannah.gnu.org>
2015-06-03 1:06 ` Stefan Monnier [this message]
2015-06-04 20:18 ` [Emacs-diffs] map 988d721: Add a pcase pattern for maps and `map-let' based on it Nicolas Petton
2015-06-04 22:39 ` Stefan Monnier
2015-06-05 8:09 ` Nicolas Petton
2015-06-07 18:36 ` Michael Heerdegen
2015-06-08 14:16 ` Stefan Monnier
2015-06-08 15:34 ` Michael Heerdegen
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=jwvbngx1unb.fsf-monnier+emacsdiffs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=nicolas@petton.fr \
/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.