Enumerations: Difference between revisions

Content added Content deleted
(Added 11l)
Line 328: Line 328:


=={{header|Delphi}}==
=={{header|Delphi}}==
In addition to [[#Pascal|standard Pascal]], one may explicitly specify an index:

<lang Delphi>type
<lang Delphi>type
TFruit = (Apple, Banana, Cherry);
fruit = (apple, banana, cherry);
ape = (gorilla = 0, chimpanzee = 1, orangutan = 5);</lang>

Note, explicit indices ''have'' to be in ascending order.
TApe = (Gorilla = 0, Chimpanzee = 1, Orangutan = 5);</lang>
You can also just specify explicit indices for ''some'' items.



=={{header|DWScript}}==
=={{header|DWScript}}==
Line 538: Line 538:
\ resistor digit colors
\ resistor digit colors
10 CONSTANTS black brown red orange yellow green blue violet gray white</lang>
10 CONSTANTS black brown red orange yellow green blue violet gray white</lang>

=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|2003}}
{{works with|Fortran|2003}}
Line 577: Line 578:
1 2 4
1 2 4
</pre>
</pre>

=={{header|Free Pascal}}==
See [[#Delphi|Delphi]].
Note, depending on the <tt>{$scopedEnum}</tt> compiler switch (as of definition time), enumeration type members are identified via the type name prepended.

Additionally, enumeration types can be passed to <tt>write</tt>/<tt>writeLn</tt> producing the Pascal (source code) identifier.


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
Line 922: Line 929:


=={{header|Lua}}==
=={{header|Lua}}==

An explicit enum can be formed by mapping strings to numbers
An explicit enum can be formed by mapping strings to numbers


Line 1,027: Line 1,033:


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==

Enumeration is done by creating a cell array (a.k.a set) of objects, where the numeral of the object is its index in the 1-based cell array. The cell array structure can contain any type of data structure including other cell arrays, and all members don't have to be the same data type.
Enumeration is done by creating a cell array (a.k.a set) of objects, where the numeral of the object is its index in the 1-based cell array. The cell array structure can contain any type of data structure including other cell arrays, and all members don't have to be the same data type.


Line 1,146: Line 1,151:


=={{header|Pascal}}==
=={{header|Pascal}}==
Standard Pascal as per ISO 7185 only allows contiguous lists of identifiers as enumerated type definitions.
See [[Enumerations#Delphi | Delphi]]
An explicit index may not be specified, but [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]] allow this.
However, it is guaranteed, that the <tt>ord</tt>inal value will correspond to the member’s position in the list (<tt>0</tt>-based).
<lang pascal>type
phase = (red, green, blue);</lang>


=={{header|Perl}}==
=={{header|Perl}}==