Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ordered-map assoc behavior to be like that of Clojure 1.5.1 #14

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jafingerhut
Copy link
Contributor

If a key is assoc'd multiple times to the same map, the first key,
along with any metadata it might have, is the one that stays in the
map. The last value assoc'd to the key is the one that is in the map,
along with any metadata it might have.

Similar behavior was added to Clojure with the commit at this link,
released with 1.5.0:

clojure/clojure@7bc871f

Refer to CLJ-1065: http://dev.clojure.org/jira/browse/CLJ-1065

If a key is assoc'd multiple times to the same map, the first key,
along with any metadata it might have, is the one that stays in the
map.  The last value assoc'd to the key is the one that is in the map,
along with any metadata it might have.

Similar behavior was added to Clojure with the commit at this link,
released with 1.5.0:

clojure/clojure@7bc871f

Refer to CLJ-1065: http://dev.clojure.org/jira/browse/CLJ-1065
@jafingerhut
Copy link
Contributor Author

Feel free to ask questions about this one, or just close it if it isn't of interest. It is a somewhat esoteric change in behavior to make ordered-maps more similar to Clojure maps in terms of how assoc works.

@amalloy
Copy link
Contributor

amalloy commented Apr 10, 2013

The behavior you describe for keys sounds weird to me. Why is it desirable to keep the first key, rather than the last key, among multiple that compare as equal?

@jafingerhut
Copy link
Contributor Author

That's a fair question. I'm not wedded to the current Clojure behavior, just an interested observer because of the changes I made with CLJ-1065 that brought the detailed behavior to my attention.

Note one thing: That is the way your ordered-sets work right now: If you try to add an item equal to an existing one, the first one stays in there with its metadata, rather than being replaced with the new equal item with the new metadata.

Doing the same for map keys, at least, seems consistent with the set behavior.

If Clojure sets and maps always replaced an existing item with a newly added equal item (and its new metadata), that would seem like reasonable behavior to me, too, but it isn't how they work today.

@slipset
Copy link
Member

slipset commented Dec 6, 2018

@jafingerhut, do you remember the status here?

@jafingerhut
Copy link
Contributor Author

I believe there is no change in status here -- everything about Clojure's detailed behavior, and the behavior of ordered sets is likely the same now as it was when I created the PR. I don't consider this a high priority change, since probably most people don't use metadata, and even if they do, they might not care so much about the detailed behavior here in Clojure's sets and maps vs. the behavior for ordered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants