Skip to content

Conversation

@danielmatz
Copy link

The design of Base.ImmutableDict allows the same key to be added again, which shadows the previously added value. Unfortunately, it still prints out all of the entries, including repeated keys. I thought this might be confusing, so I implemented it to remove the value if the key exists and then add the new value.

Closes #216

@danielmatz
Copy link
Author

I'm going to wait for the conversation on my PR to implement Base.setindex to play out, since that will likely influence how we should implement this method here.

The design of Base.ImmutableDict allows the same key to be added again, which
shadows the previously added value. Unfortunately, it still prints out all of
the entries, including repeated keys. I thought this might be confusing, so I
implemented it to remove the value if the key exists and then add the new value.

Closes JuliaObjects#216
@danielmatz
Copy link
Author

Based on the discussion about Base.setindex, it seems that ImmutableDict was intended to behave like a multi-dict. So, existing keys should remain. I updated this branch to not remove existing duplicate keys.

Copy link

@cstjean cstjean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uneasy about that one, but it's the Base behaviour...

@aplavin
Copy link
Member

aplavin commented Oct 26, 2025

I suggest we wait for JuliaLang/julia#59880 to be approved, to make sure we won't need to change the semantics afterwards.
Unless it's urgent for @danielmatz?

@danielmatz
Copy link
Author

This isn't urgent for me at all.

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.

Add support for Base.ImmutableDict

3 participants