GNU bug report logs - #49407
Request: Specify default values in `map-let` in Map.el

Previous Next

Package: emacs;

Reported by: Okam <okamsn <at> protonmail.com>

Date: Sun, 4 Jul 2021 23:10:01 UTC

Severity: wishlist

Fixed in version 30.1

Done: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Okam <okamsn <at> protonmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>, Nicolas Petton <nicolas <at> petton.fr>
Cc: 49407 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#49407: Request: Specify default values in `map-let` in Map.el
Date: Fri, 21 Jul 2023 02:56:19 +0000
[Message part 1 (text/plain, inline)]
On 2021-07-15 08:51 UTC, Lars Ingebrigtsen wrote:
> Okam <okamsn <at> 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 (text/x-patch, attachment)]

This bug report was last modified 2 years and 2 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.