Linear order protocol
Factor handbook » The language » Objects

Prev:Equality
Next:Classes

Some classes define an intrinsic order amongst instances. This includes numbers, sequences (in particular, strings), and words.
<=> ( obj1 obj2 -- <=> )
>=< ( obj1 obj2 -- >=< )
compare ( obj1 obj2 quot -- <=> )
invert-comparison ( <=> -- >=< )

The above words output order specifiers.
Ordering specifiers

Utilities for comparing objects:
after? ( obj1 obj2 -- ? )
before? ( obj1 obj2 -- ? )
after=? ( obj1 obj2 -- ? )
before=? ( obj1 obj2 -- ? )

Minimum, maximum, clamping:
min ( obj1 obj2 -- obj )
max ( obj1 obj2 -- obj )
clamp ( x min max -- y )

Out of the above generic words, it suffices to implement <=> alone. The others may be provided as an optimization.
Linear order example

See also
Sorting sequences