ENUM:
Factor handbook > C library interface > Passing data between Factor and C > Enumeration types

Next:define-enum ( word base-type members -- )


Vocabulary
alien.syntax

Syntax
ENUM: type words... ; ENUM: type < base-type words...


Inputs and outputs
typea name to typedef to int or f
wordsa sequence of word names


Word description
Creates a c-type that boxes and unboxes integer values to symbols. A symbol is defined for each member word. 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:
ENUM: tv_peripherals_1 < uchar { appletv 1 } { chromecast 2 } { roku 4 } ;

The same as above but four bytes instead of one:
ENUM: tv_peripherals_4 < uint { appletv 1 } { chromecast 2 } { roku 4 } ;


See also
define-enum, enum>number, number>enum

Definition