Skip to content

v2.5.0: Tuple classes; easier lexicographic ordering; bijections

Latest

Choose a tag to compare

@slburson slburson released this 15 Aug 00:34

v2.5.0 adds a few minor features.

Tuple classes

define-tuple-class allows you to create subclasses of fset: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 that with and less operations on them return a new instance of the same class.

The syntax of define-tuple-class is very similar to that of defstruct, 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 by with and less, 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 had compare-lexicographically to 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, and wb-lexi-map to 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 a lookup-inv method that returns the key for a given value, and an inverse method that returns a new bijection with keys and values swapped.