Skip to content

Equality defined between builtin collections respect partitions #558

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

Merged
merged 5 commits into from
Jun 11, 2020

Conversation

chrisrink10
Copy link
Member

@chrisrink10 chrisrink10 commented Jun 11, 2020

This PR corrects the equality operators between builtin collection types to respect equality partitions. Equality partitions are segments of different collections within which collections can be considered equal and between which collections cannot be considered equal. The three equality partitions are: sequential types (vectors, seqs), maps, and sets.

Several other small changes were made in support of that goal:

  • Map types now properly support the full Python Mapping protocol.
    • Map.__iter__ now acts like a standard Python Mapping type, returning an iterable of keys. Formerly, it was an iterable of MapEntry types, which was occasionally convenient, but definitely un-idiomatic in Python. This change doesn't really affect Basilisp code though, since Basilisp always calls .seq() on maps to iterate over entries.
    • Removed the .iteritems(), .iterkeys(), and .itervalues() methods which simply forwarded to the base pyrsistent.PMap implementation.
    • Mapping.items(), .keys(), and .values() are now supported. All cases relying on the former __iter__ implementation have generally been updated to use .items() (though a few cases were updated to use .seq()).
  • All builtin ISeq types and IPersistentVector have been annotated with the marker interface ISequential which is attached to all sequential types in that equality partition.
  • IPersistentVector types are no longer considered Mapping types, though they are still considered IAssociative. It never really made sense to consider them Mapping types and it was generally inconvenient since it is not useful to consider vectors as maps in most cases.
  • Removed the custom Vector.rseq() implementation since it was undoubtedly no more efficient than Python's reversed using the Python Sequence protocol.

Two small fixes unrelated to the main changes were also included because I was already in the code:

  • basilisp.core/rest now never returns nil. Instead, it returns the empty seq in any case it would formerly return nil.
  • I fixed a deprecation with the PyTest plugin that emitted Warnings every time any Basilisp tests ran.

References:

Fixes #556

@chrisrink10 chrisrink10 merged commit 844ba29 into master Jun 11, 2020
@chrisrink10 chrisrink10 deleted the fix/equality-partitions branch June 11, 2020 12:51
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.

= for collections does not respect equality partitions
1 participant