Sequence protocol - Factor Documentation (original) (raw)
All sequences must be instances of a mixin class: sequence
sequence? ( object -- ? )
All sequences must know their length:
At least one of the following two generic words must have a method for accessing elements; the sequence mixin has default definitions which are mutually recursive:
nth-unsafe ( n seq -- elt )
?nth ( n seq -- elt/f )
Note that sequences are always indexed starting from zero.
At least one of the following two generic words must have a method for storing elements; the sequence mixin has default definitions which are mutually recursive:
set-nth-unsafe ( elt n seq -- )
?set-nth ( elt n seq -- )
If your sequence is immutable, then you must implement either set-nth or set-nth-unsafe to simply call immutable to signal an error.
The following two generic words are optional, as not all sequences are resizable:
An optional generic word for creating sequences of the same class as a given sequence:
like ( seq exemplar -- newseq )
Optional generic words for optimization purposes:
new-sequence ( len seq -- newseq )
new-resizable ( len seq -- newseq )
See also
Unsafe sequence operations