Tuple arrays


The tuple-arrays vocabulary implements space-efficient unboxed tuple arrays. Whereas an ordinary array of tuples would consist of references to heap-allocated objects, a tuple array stores its elements as values.

Calling nth copies an element into a new tuple, and calling set-nth copies an existing tuple's slots into an array.

Since value semantics are incompatible with inheritance, the base type of a tuple array must be declared final. A best practice that is not enforced is to have all slots in the tuple declared read-only.

Tuple arrays do not get updated if tuples are redefined to add or remove slots, so caution should be exercised when doing interactive development on code that uses tuple arrays.

TUPLE-ARRAY:


An example:
USE: tuple-arrays IN: scratchpad TUPLE: point x y ; final TUPLE-ARRAY: point { T{ point f 1 2 } T{ point f 1 3 } T{ point f 2 3 } } >point-array first short.
T{ point f 1 2 }