Ada
In Ada, the use of "=" was replaced with "is" leaving the definition quite similar:
type Cardsuit is (clubs, diamonds, hearts, spades);In addition to Pred
, Succ
, Val
and Pos
Ada also supports simple string conversions via Image
and Value
.
Similar to C-style languages Ada allows the internal representation of the enumeration to be specified:
for Cardsuit use (clubs => 1, diamonds => 2, hearts => 4, spades => 8);Unlike C-style languages Ada also allows the number of bits of the enumeration to be specified:
for Cardsuit'Size use 4; -- 4 bitsEven more, you can use enumerations as indexes for arrays like pascal, but there are attributes defined for enumerations
Shuffle : constant array(Cardsuit) of Cardsuit := (Clubs => Cardsuit'Succ(Clubs), -- see attributes of enumerations 'First, 'Last, 'Succ, 'Pred Diamonds => Hearts, --an explicit value Hearts => Cardsuit'Last, --first enumeration value of type Cardsuit e.g. clubs Spades => Cardsuit'First --last enumeration value of type Cardsuit e.g. spades );Like Modula-3 Ada treats Boolean
and Character
as special pre-defined (in package "Standard
") enumerated types. Unlike Modula-3 one can also define own character types:
Read more about this topic: Enumerated Type, Pascal and Syntactically Similar Languages