Closed LeXofLeviafan closed 6 years ago
@LeXofLeviafan I'm not actively using EDN any more, so I don't know if I'll get around to this. In the meanwhile, pull requests are welcome.
Fixes by #50.
@swaroopch Why have you decided to implement and use ImmutableDict and ImmutableList instead of plain dict and list?
@adam0z
Why have you decided to implement and use ImmutableDict and ImmutableList instead of plain dict and list?
The change was made in https://github.com/swaroopch/edn_format/commit/84c308300355b68af144a083fb32078d02d9472c and I don't think the reason was documented.
IIRC, it was related to https://github.com/edn-format/edn#rationale :
edn will yield distinct object identities when read, unless a reader implementation goes out of its way to make such a promise. Thus the resulting values should be considered immutable, and a reader implementation should yield values that ensure this, to the extent possible.
Now, emitting mutable values may or may not be an issue depending on the point of view, but since you went to the trouble of implementing immutable dicts, you probably want them to be completely immutable.
...Also, Python lists are unhashable, so both "{[1 2 3] 5}" and "#{[1 2 3] 5}" generate TypeError.
Proposed solution is to add a corresponding class (named, for example, ImmutableVector), implemented in similar fashion to ImmutableDict; however, whether it extends list or not (it would make sense to implement it using tuples), it would break code that mutates parsed vectors.