Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!wuarchive!usc!apple!snorkelwacker!spdcc!ima!esegue!compilers-sender From: moss@cs.umass.edu (Eliot Moss) Newsgroups: comp.compilers Subject: Re: Enumerated data types Keywords: modula, design, types Message-ID: Date: 24 Aug 90 14:18:26 GMT References: <1990Aug23.134826.2865@forwiss.uni-passau.de> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: moss@cs.umass.edu (Eliot Moss) Organization: Dept of Comp and Info Sci, Univ of Mass (Amherst) Lines: 34 Approved: compilers@esegue.segue.boston.ma.us In-Reply-To: mandel@forwiss.uni-passau.de's message of 23 Aug 90 13:48: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 -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.