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: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 49407 <at> debbugs.gnu.org, Nicolas Petton <nicolas <at> petton.fr>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#49407: Request: Specify default values in `map-let` in Map.el
Date: Sat, 22 Jul 2023 18:46:12 +0000
[Message part 1 (text/plain, inline)]
On 2023-07-22 01:48 UTC, Michael Heerdegen wrote:
> 
> | diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
> | index 7a48ba47434..7f127f312de 100644
> | --- a/lisp/emacs-lisp/map.el
> | +++ b/lisp/emacs-lisp/map.el
> | @@ -50,18 +50,23 @@ map
> |
> |  ARGS is a list of elements to be matched in the map.
> |
> | -Each element of ARGS can be of the form (KEY PAT), in which case KEY is
> | -evaluated and searched for in the map.  The match fails if for any KEY
> | -found in the map, the corresponding PAT doesn't match the value
> | -associated with the KEY.
> | +Each element of ARGS can be of the form (KEY PAT) or (KEY PAT DEFAULT),
> | +
> | +in which case KEY is evaluated and searched for in the map and
> 
> That line break in the last sentence is somehow... broken.
> 
> | +DEFAULT is the evaluated value used if KEY is not found.  The
> | +match fails if for any KEY found in the map, the corresponding
> | +PAT doesn't match the value associated with the KEY.  The match
> | +fails if for any KEY not found in the map, the corresponding PAT
> | +doesn't match the DEFAULT value, if given.
> 
> Here is something grammatically not right in the last sentence.  And I
> think we should say that that last case (PAT doesn't match DEFAULT) only
> lets matching fail when the KEY is not found.
> 
> 
> | -Keys in ARGS not found in the map are ignored, and the match doesn't
> | -fail."
> | +When no DEFAULT value is given, the default value for keys in
> | +ARGS not found in the map is nil, and the match doesn't fail so
> | +long at PAT, if given, matches nil."
> |    `(and (pred mapp)
> |          ,@(map--make-pcase-bindings args)))
> 
> Typo in doc ("at").  And can't we simply say that omitting DEFAULT is
> equivalent to a DEFAULT of nil?
> 
> | @@ -599,7 +606,11 @@ map--make-pcase-bindings
> |    "Return a list of pcase bindings from ARGS to the elements of a map."
> |    (mapcar (lambda (elt)
> |              (cond ((consp elt)
> | -                   `(app (pcase--flip map-elt ,(car elt)) ,(cadr elt)))
> | +                   (if (cddr elt)
> | +                       `(app (lambda (arg)
> | +                               (map-elt arg ,(car elt) ,(caddr elt)))
> | +                             ,(cadr elt))
> | +                     `(app (pcase--flip map-elt ,(car elt)) ,(cadr elt))))
> 
> If we don't extend `pcase--flip' to support this case, I think your
> lambda would need to use an uninterned symbol as parameter to avoid
> collisions with the involved expressions.
> 
> 
> Michael.

Please see the attached file. I have re-worded the doc string and added 
a wrapper macro to re-order the arguments to `map-elt` for the `app` 
pattern.
[v2-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.