Enumerations: Difference between revisions

(Added 11l)
Line 328:
 
=={{header|Delphi}}==
In addition to [[#Pascal|standard Pascal]], one may explicitly specify an index:
 
<lang Delphi>type
TFruit fruit = (Appleapple, Bananabanana, Cherrycherry);
TApe ape = (Gorillagorilla = 0, Chimpanzeechimpanzee = 1, Orangutanorangutan = 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}}==
Line 538:
\ resistor digit colors
10 CONSTANTS black brown red orange yellow green blue violet gray white</lang>
 
=={{header|Fortran}}==
{{works with|Fortran|2003}}
Line 577 ⟶ 578:
1 2 4
</pre>
 
=={{header|Free Pascal}}==
See [[Enumerations#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#}}==
Line 922 ⟶ 929:
 
=={{header|Lua}}==
 
An explicit enum can be formed by mapping strings to numbers
 
Line 1,027 ⟶ 1,033:
 
=={{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.
 
Line 1,146 ⟶ 1,151:
 
=={{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}}==
149

edits