GNU bug report logs - #50927
Considering only entries with unique keys in map.el?

Previous Next

Package: emacs;

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

Date: Fri, 1 Oct 2021 00:56:01 UTC

Severity: normal

Tags: notabug

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50927 in the body.
You can then email your comments to 50927 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#50927; Package emacs. (Fri, 01 Oct 2021 00:56:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Okamsn <okamsn <at> protonmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 01 Oct 2021 00:56:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Okamsn <okamsn <at> protonmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Considering only entries with unique keys in map.el?
Date: Fri, 01 Oct 2021 00:55:21 +0000
[Message part 1 (text/plain, inline)]
Some kinds of maps, such as alists and plists, can contain duplicate
keys.  These duplicates are effectively ignored in functions like
`map-elt`, but are not ignored in functions like `map-do` or `map-length`.

To me, it would make more sense if these functions only considered the
valid entries in the map.  For example,

    (map-pairs '(a 1 b 2 a 3))

currently returns '((a . 1) (b . 2) (a . 3)), even though '(a . 3) is
meant to be ignored in actual usage, as it is preceded by an earlier
entry with the same key.  This is a misleading behavior.

I do not know whether the current behavior is desirable.  Is it?

Please consider changing the library so that the duplicate,
meant-to-be-ignored entries are actually ignored for functions that
operate on the entire map.

I have attached an example diff.

Thank you.


[map-uniq.diff (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50927; Package emacs. (Fri, 01 Oct 2021 01:57:02 GMT) Full text and rfc822 format available.

Message #8 received at 50927 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Okamsn <okamsn <at> protonmail.com>, "50927 <at> debbugs.gnu.org"
 <50927 <at> debbugs.gnu.org>
Subject: RE: [External] : bug#50927: Considering only entries with unique keys
 in map.el?
Date: Fri, 1 Oct 2021 01:56:10 +0000
> Some kinds of maps, such as alists and plists, can contain duplicate
> keys.  These duplicates are effectively ignored in functions like
> `map-elt`, but are not ignored in functions like `map-do` or `map-
> length`.
> 
> To me, it would make more sense if these functions only considered the
> valid entries in the map.  For example,
> 
>     (map-pairs '(a 1 b 2 a 3))
> 
> currently returns '((a . 1) (b . 2) (a . 3)), even though '(a . 3) is
> meant to be ignored in actual usage,

But you, yourself, just said that some functions
don't ignore it.  So it's not an "invalid" entry.

This all comes from Lisp being untyped.  The same
list can serve different uses, some of which are
maps that don't allow duplicates (i.e., they're
functions, not relations).

It's not an error that "these functions" (depending
on which you mean) consider all list elements.

> entry with the same key.  This is a misleading behavior.

Actually, it's a handy behavior.  It's one of the
main ideas behind alists.  You can just remove or
skip the first match of a given key to restore or
use the next one.

My comments aren't really for `map-*' functions,
as I'm not familiar with them.  I'm just commenting
on what you said in general.  HTH.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50927; Package emacs. (Fri, 01 Oct 2021 02:18:01 GMT) Full text and rfc822 format available.

Message #11 received at 50927 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: Okamsn <okamsn <at> protonmail.com>,
 "50927 <at> debbugs.gnu.org" <50927 <at> debbugs.gnu.org>
Subject: Re: bug#50927: [External] : bug#50927: Considering only entries
 with unique keys in map.el?
Date: Fri, 01 Oct 2021 04:17:12 +0200
Drew Adams <drew.adams <at> oracle.com> writes:

> > entry with the same key.  This is a misleading behavior.
>
> Actually, it's a handy behavior.  It's one of the main ideas behind
> alists.  You can just remove or skip the first match of a given key to
> restore or use the next one.

I tend to agree.  And it's easy to avoid duplicate entries - they
are not introduced when using the map.el functions the right way.

OTOH: the map looping or do- tools also useful for inspecting duplicates
- this is useful.  Avoiding duplicates would also mean O(n^2) equality
tests per map - right?

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50927; Package emacs. (Fri, 01 Oct 2021 12:49:01 GMT) Full text and rfc822 format available.

Message #14 received at 50927 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Okamsn <okamsn <at> protonmail.com>
Cc: 50927 <at> debbugs.gnu.org
Subject: Re: bug#50927: Considering only entries with unique keys in map.el?
Date: Fri, 01 Oct 2021 14:48:07 +0200
Okamsn <okamsn <at> protonmail.com> writes:

> Some kinds of maps, such as alists and plists, can contain duplicate
> keys.  These duplicates are effectively ignored in functions like
> `map-elt`, but are not ignored in functions like `map-do` or `map-length`.

As others have noted, this is part of how alists (etc) work, and we
can't change that -- it would break tons of code.

If you don't want duplicate keys, then you should only use functions
like `map-insert' etc to work on the maps.

So I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) notabug. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 01 Oct 2021 12:49:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 50927 <at> debbugs.gnu.org and Okamsn <okamsn <at> protonmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Fri, 01 Oct 2021 12:49:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 30 Oct 2021 11:24:05 GMT) Full text and rfc822 format available.

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

Previous Next


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