Enumeration element syntax
Enumeration classes

Prev:define-enum-class ( class superclass member-list -- )
Next:enumeration-class


Enumeration elements are typically specified by their name, as in
ENUMERATION: example first-elt second-elt ;

but they can also be specified using an array. The second element of this array is the value assigned to the enum element, and is used as the counter that subsiquent elements increment from
USING: prettyprint classes.enumeration ; ENUMERATION: example first-elt { second-elt 10 } third-elt ; example.first-elt . example.second-elt . example.third-elt .
0 10 11

The third element of the array, if present, must be a quotation. It defines how subsiquent increments are handled. By default, incrementation means that 1 is added to the counter to get the value of the next element. This quotation changes that definition.
USING: prettyprint math classes.enumeration ; ENUMERATION: example first-elt second-elt { third-elt 3 [ 2 * ] } fourth-elt fifth-elt ; example.third-elt . example.fourth-elt . example.fifth-elt .
3 6 12

Despite their name, enumeration values do not just have to be numbers, although if these values don't support math operations, you'll need to define a custom incrementation quotation and starting value.
IN: enumeration-demo USING: classes.enumeration prettyprint strings sequences ; ENUMERATION: example-enum3 < string { example-elt1 "a" [ CHAR: a suffix ] } example-elt2 ; example-enum3.example-elt2 .
"aa"


See also
ENUMERATION:, Enumeration classes