ENUM: type words... ;
ENUM: type < base-type words...
Inputs None
Outputs None
Word description
Warning This word is part of Factor's C library interface, and not intended for use with Factor data. Factor has its own native Enumerations which can be created with <enumerated>.
Creates a c-type that boxes and unboxes integer values to symbols. A singleton is defined for each member word which allows generic dispatch on the enum's members. The base c-type can optionally be specified and defaults to int. A constructor word <type> is defined for converting from integers to singletons. The generic word enum>number converts from singletons to integers. Enum-typed values are automatically prettyprinted as their singleton words. Unrecognizing enum numbers are kept as numbers.
Examples Here is an example enumeration definition:
ENUM: color_t red { green 3 } blue ;
The following expression returns true:
3 <color_t> [ green = ] [ enum>number 3 = ] bi and
Here is a version where the C-type takes a single byte: