Coercive slot declarations
Factor handbook » The language » Objects » Tuples » Tuple slot declarations » Slot class declarations


If the class of a slot is declared to be one of fixnum or float, then rather than testing values with the class predicate, writer words coerce values to the relevant type with >fixnum or >float. This may still result in error, but permits a wider range of values than a class predicate test. It also results in a possible loss of precision; for example, storing a large integer into a fixnum slot will silently overflow and discard high bits, and storing a ratio into a float slot may lose precision if the ratio is one which cannot be represented exactly with floating-point.

This feature is mostly intended as an optimization for low-level code designed to avoid integer overflow, or where floating point precision is sufficient. Most code needs to work transparently with large integers, and thus should avoid the coercion behavior by using integer and real in place of fixnum and float.