[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#49407: Request: Specify default values in `map-let` in Map.el
From: |
Okam |
Subject: |
bug#49407: Request: Specify default values in `map-let` in Map.el |
Date: |
Fri, 21 Jul 2023 02:56:19 +0000 |
On 2021-07-15 08:51 UTC, Lars Ingebrigtsen wrote:
> Okam <okamsn@protonmail.com> writes:
>
>> `map-let` allows one to conveniently bind variables using `map-elt`, but
>> does not provide a way specify a default value if a key is missing.
>>
>> With `map-elt`, one can use the optional third argument to specify this
>> value. It would be good to have this in `map-let` as well.
>>
>> For example, maybe it could look something like
>>
>> ;; As just a third value in the list:
>> (let ((map '(:a 1 :b 2)))
>> (map-let ((:a a)
>> (:b b)
>> (:c c 3))
>> map
>> (+ a b c)))
>
> Hm... I guess that could be useful. I've added Nicolas to the CCs;
> perhaps he has an opinion here.
>
> --
> (domestic pets only, the antidote for overdose, milk.)
> bloggy blog: http://lars.ingebrigtsen.no
Hello,
I've written a patch and tests that would add an optional third argument
for a default value. I also changed the documentation string for the
pcase pattern, which said that unfound keys are ignored and won't cause
the pattern to fail. That didn't seem true for patterns that didn't
match nil. For example, this won't match:
(pcase '(:two 2)
((map (:two two 33)
(:three `(,a . ,b)))
(list two a b))
(_ 'fail))
However, I have a question about avoiding using a lambda. I see that the
pattern uses `pcase--flip`, which is "used internally to avoid (funcall
(lambda ...) ...)". Why should lambda functions be avoided for this, and
I should be using a custom helper function for this one pattern?
Thank you.
0001-Allow-default-values-in-map-let-and-the-pcase-map-fo.patch
Description: Text Data
- bug#49407: Request: Specify default values in `map-let` in Map.el,
Okam <=
- bug#49407: Request: Specify default values in `map-let` in Map.el, Michael Heerdegen, 2023/07/21
- bug#49407: Request: Specify default values in `map-let` in Map.el, Stefan Monnier, 2023/07/22
- bug#49407: Request: Specify default values in `map-let` in Map.el, Okam, 2023/07/22
- bug#49407: Request: Specify default values in `map-let` in Map.el, Michael Heerdegen, 2023/07/25
- bug#49407: Request: Specify default values in `map-let` in Map.el, Okam, 2023/07/26
- bug#49407: Request: Specify default values in `map-let` in Map.el, Basil L. Contovounesios, 2023/07/28
- bug#49407: Request: Specify default values in `map-let` in Map.el, Eli Zaretskii, 2023/07/28
- bug#49407: Request: Specify default values in `map-let` in Map.el, Okam, 2023/07/28
- bug#49407: Request: Specify default values in `map-let` in Map.el, Basil L. Contovounesios, 2023/07/30
- bug#49407: Request: Specify default values in `map-let` in Map.el, Michael Heerdegen, 2023/07/31