Enumerations: Difference between revisions

Content added Content deleted
Line 272: Line 272:
=={{header|ATS}}==
=={{header|ATS}}==


The wording of the task is C-centric, where an ''enum'' is a sort of integer, but it is true that the following type will be translated by the ATS compiler to C integers:
The wording of the task seems centered on C, where an '''enum''' is a notation for type '''int''', but it is true that the following type will be translated by the ATS compiler to C integers:


<lang ATS>datatype my_enum =
<lang ATS>datatype my_enum =
Line 279: Line 279:
| value_c</lang>
| value_c</lang>


Within ATS itself, it is a special case of recursive type definition. Similar facilities are available in ML dialects and other languages.
To do it with explicit values, I would simply define some constants, probably with '''#define''' (so I could use them in static expressions, etc.):

To "enumerate" with explicit integer values, I would simply define some constants, probably with '''#define''' (so I could use them in static expressions, etc.):
<lang ATS>#define value_a 1
<lang ATS>#define value_a 1
#define value_b 2
#define value_b 2