Enumerated Type

In computer programming, an enumerated type (also called enumeration or enum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but which do not have any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.

For example, the four suits in a deck of playing cards may be four enumerators named CLUB, DIAMOND, HEART, SPADE, belonging to an enumerated type named suit. If a variable V is declared having suit as its data type, one can assign any of those four values to it.

The enumerators are necessarily distinct, even though some languages may allow the same enumerator to be listed twice in the type's declaration. The enumerators need not be complete or compatible in any sense. For example, an enumerated type called color may be defined to consist of the enumerators RED, GREEN, ZEBRA, MISSING, CHUCK NORRIS and BACON. In some languages, the declaration of an enumerated type also defines an ordering of its members.

Some enumerator types may be built into the language. The Boolean type, for example is often a pre-defined enumeration of the values FALSE and TRUE. Many languages allow the user to define new enumerated types.

Values and variables of an enumerated type are usually implemented as fixed-length bit strings, often in a format and size compatible with some integer type. Some languages, especially system programming languages, allow the user to specify the bit combination to be used for each enumerator. In type theory, enumerated types are often regarded as tagged unions of unit types. Since such types are of the form, they may also be written as natural numbers.

Read more about Enumerated Type:  Rationale, Conventions, Pascal and Syntactically Similar Languages, C and Syntactically Similar Languages, Fortran, Visual Basic/VBA, Algebraic Data Type in Functional Programming, Lisp, Databases, XML

Famous quotes containing the word type:

    Under the species of Syndicalism and Fascism there appears for the first time in Europe a type of man who does not want to give reasons or to be right, but simply shows himself resolved to impose his opinions.
    José Ortega Y Gasset (1883–1955)