Repository navigation
v2.5.0: Tuple classes; easier lexicographic ordering; bijections #126
slburson
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
v2.5.0 adds a few minor features.
Tuple classes
define-tuple-classallows you to create subclasses offset:dyn-tuple. This is mostly to allow you to define methods on them. Tuple classes are structure classes, and so support only single inheritance. Instances of these classes behave like ordinary dynamic tuples, except thatwithandlessoperations on them return a new instance of the same class.The syntax of
define-tuple-classis very similar to that ofdefstruct, but there are some restrictions; see the doc string for details.Tuple classes can have ordinary slots also, which are mutable unless declared
:read-only t. By default, the values of ordinary slots are copied to the new instances created bywithandless, but you can turn this off by declaring the slot:discard-on-copy t.Easier lexicographic ordering
The default ordering used by the WB types (
wb-set,wb-bag,wb-map, etc.) orders by size first; so, "B" comes before "AA". This is done for performance, but if the collection is one that will be displayed in order to users, you may prefer to keep it in lexicographic (dictionary) ordering, in which "AA" comes before "B". FSet already hadcompare-lexicographicallyto support this, but it didn't work for symbols, it didn't recursively default to lexicographic comparison for the elements of sequences, and of course, the name was too damn long.So I have renamed it to
compare-lexi(the old name still works, of course, except that it's now a non-generic function; if you've defined any methods on it, you'll need to rename them) and added symbol support. I've also made it default to calling itself recursively on elements of sequences.I've also added constructor macros
wb-lexi-set,wb-lexi-bag, andwb-lexi-mapto make it more convenient to create collections with this ordering.Bijections
I have added a partial, somewhat experimental implementation of bijections. These are maps with the additional constraint that no two keys may map to the same value. They don't have defaults; lookup on a key not in the bijection signals an error, but you can use
contains?to check whether a key is present. They have alookup-invmethod that returns the key for a given value, and aninversemethod that returns a new bijection with keys and values swapped.This discussion was created from the release v2.5.0: Tuple classes; easier lexicographic ordering; bijections.
All reactions