Chapter 8

Collections

Mutability

Some collections can be modified after they have been created while others cannot. The <mutable-collection> and <stretchy-collection> mixin classes are provided to allow methods to distinguish between mutable and immutable collections. Instances of <mutable-collection> can have their elements changed after they are created. Instances of <stretchy-collection> can have keys added and removed after they are created.

An element of a mutable collection is set to a new value with element-setter. If the collection is not stretchy, then the key specified must already be present in the collection; its value will be changed. If the collection is stretchy, then the key will be added if it is not already present. If the collection is a stretchy sequence and the key is not already present, then the size of the sequence will first be set to the new key plus 1, and then the value of the new key will be set.

A key and its corresponding value can be removed from an explicit key collection with the function remove-key!.