Related articles |
---|
Enumerated data types mandel@forwiss.uni-passau.de (1990-08-23) |
Re: Enumerated data types moss@cs.umass.edu (1990-08-24) |
Re: Enumerated data types skrenta@amix.commodore.com (1990-08-15) |
Re: Enumerated data types dik@cwi.nl (1990-08-24) |
Re: Enumerated data types ok@goanna.cs.rmit.OZ.AU (1990-08-27) |
Re: Enumerated data types jejones@microware.com (1990-08-27) |
Re: Enumerated data types perelgut@turing.toronto.edu (1990-08-24) |
Re: Enumerated data types dik@cwi.nl (1990-08-27) |
[5 later articles] |
Newsgroups: | comp.compilers |
From: | moss@cs.umass.edu (Eliot Moss) |
In-Reply-To: | mandel@forwiss.uni-passau.de's message of 23 Aug 90 13:48:26 GMT |
Keywords: | modula, design, types |
Organization: | Dept of Comp and Info Sci, Univ of Mass (Amherst) |
References: | <1990Aug23.134826.2865@forwiss.uni-passau.de> |
Date: | 24 Aug 90 14:18:26 GMT |
What you suggest has indeed been done in the Modula-3 language. One can write
down two types such as (the syntax may not be exact; I don't have my Modula-3
Report here at home):
TYPE t1 = ENUM red, black END;
t2 = ENUM green, yellow, red END;
To mention the constants anywhere one must write t1.red, t1.black, t2.green,
t2.yellow, or t2.red. Thus there is no ambiguity. It is quite reasonable to
write SUCC (t2.green). There is an ORD function (ORD (t1.red) = 0, etc.) and
a VAL function (VAL (t2, 1) = t2.yellow), etc. It is specifically illegal, and
must be detected at run-time, if an attempt is made to go out of range with
VAL, SUCC, PRED, etc. There are INC and DEC operators that work on
enumerations as well as integers; enumerations may be bit packed; and you can
ask for the number of values of an enumeration type or variable (NUMBER (t2) =
3). This all seems to work nicely.
Ada also allows multiple types to use the same name, and if a particular
enumeration constant identifier is ambiguous in context, then it can be
qualified (e.g., t2'red) to disambiguate. The Ada overloading may be a little
more convenient for writing, but the Modula-3 approach has the advantage that
adding a new enumeration type in a particular scope never breaks the existing
code.
Cheers! Eliot
--
J. Eliot B. Moss, Assistant Professor
Department of Computer and Information Science
Lederle Graduate Research Center
University of Massachusetts
Amherst, MA 01003
(413) 545-4206; Moss@cs.umass.edu
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.