[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Emacs-diffs] map 988d721: Add a pcase pattern for maps and `map-let
From: |
Nicolas Petton |
Subject: |
Re: [Emacs-diffs] map 988d721: Add a pcase pattern for maps and `map-let' based on it |
Date: |
Thu, 04 Jun 2015 22:18:06 +0200 |
Stefan Monnier writes:
>> + "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.
Yes, and there's a typo. It should be "[...] or a list of keys.".
>
>> + (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).
Yes, exactly.
> 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.
Why not, I don't have a strong opinion, and I think both would work.
> - Use a plist rather than an alist. I like alists better in general, so
> I'm fine with this choice.
Yes, I think it's better than a plist.
> - 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.
Do you think it would be worth it? I'm not sure.
Cheers,
Nico
--
Nicolas Petton
http://nicolas-petton.fr
signature.asc
Description: PGP signature