GNU bug report logs -
#49407
Request: Specify default values in `map-let` in Map.el
Previous Next
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
Message #43 received at 49407 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Basil L. Contovounesios wrote:
> Okam via "Bug reports for GNU Emacs, the Swiss army knife of text editors" [2023-07-27 01:39 +0000] wrote:
>
>> From 99208ca640d4944c57082772702cb8534fe91d32 Mon Sep 17 00:00:00 2001
>> From: Earl Hyatt <okamsn <at> protonmail.com>
>
> I think your past contributions were under "Earl Hyatt
> <ej32u <at> protonmail.com>", right? Is okamsn <at> protonmail.com your current
> address? Eli, does it make a difference for the CA, do we need to
> update .mailmap, or anything like that?
Yes, I changed addresses. The mailmap makes it look like I used the old
address in `git log`. Would it be OK to make it so that the old address
shows as the new one instead?
>> Date: Thu, 20 Jul 2023 21:44:41 -0400
>> Subject: [PATCH v3] Allow default values in 'map-let' and the pcase 'map' form
>>
>> * lisp/emacs-lisp/map.el (map-let, map)
>> (map--make-pcase-bindings): Add a third argument for specifying a
>> default value, like in 'map-elt'. (Bug#49407)
>>
>> * lisp/emacs-lisp/map.el (map--make-pcase-bindings): Clarify that keys
>> that aren't found aren't ignored, they actually get the value
>> nil (unless the new default value is given). The overall pattern can
> ^^
> Two spaces here.
Fixed.
>> +Each element in ARGS can be of the form (KEY PAT) or (KEY PAT
>> +DEFAULT), where KEY is the key sought in the map, PAT is a
>> +`pcase' pattern, and DEFAULT is the default value to use if KEY
>> +isn't found. Both KEY and DEFAULT are evaluated. If DEFAULT
>> +isn't given, then nil is used.
>
> FWIW, the form/structure can be kept on a single line, and a couple of
> passive voices avoided, by rewording as e.g.
>
> Each element of ARGS can be of the form (KEY PAT [DEFAULT]),
> which looks up KEY in the map and matches the associated value
> against `pcase' pattern PAT. DEFAULT specifies the fallback
> value to use when KEY is not present in the map. If omitted, it
> defaults to nil. Both KEY and DEFAULT are evaluated.
I have changed it to this.
>> +The match fails if:
>> +
>> +- KEY is found and PAT does not match the associated value
>> +
>> +- KEY is not found, DEFAULT is given, and PAT does not match
>> + DEFAULT
>> +
>> +- KEY is not found, DEFAULT is not given, and PAT does not match
>> + nil"
>
> I find this partly redundant/repetitive, since we already know that PAT
> is meant to match either KEY's value (when found), or DEFAULT (which
> defaults to nil).
>
> What this doesn't make explicit (compared to the previous version) is
> what happens when there are multiple ARGS; specifically, when one or
> more of them don't match.
I changed it to "An element of ARGS fails to match if PAT does not match
the associated value or the default value. The overall pattern fails
to match if any element of ARGS fails to match." Does that work?
>> +KEYS can also be a list of (KEY VARNAME) pairs and
>> +\(KEY VARNAME DEFAULT) triples, in which case KEY and
>
> This could also use (KEY VARNAME [DEFAULT]) syntax, if preferred.
Changed.
Thank you.
[v4-0001-Allow-default-values-in-map-let-and-the-pcase-map.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.