From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,MSGID_SHORT autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 31 Jul 91 23:46:43 GMT From: sampson@cod.nosc.mil (Charles H. Sampson) Subject: Re: Question on enumeration types Message-ID: <3208@cod.NOSC.MIL> List-Id: In article <1991Jul31.003524.1589@csc.canterbury.ac.nz> rjm@cantua.canterbury.a c.nz (insane) writes: >In an article I'm currently reading [David Moffat; "Enumerations in Pascal, Ad a, and Beyond"; from: SIGPLAN 16.2 1981 pp77-82] there is an example which invo lves two anonymous declarations of the same enumeration type: > > flag: (up, down); >and > semaphore: (up, down); > >('semaphore' may have been defined in the same or a nested scope). >Moffat then states that neither variable can be used, "... because any >occurrences of the constants 'up' and 'down' must now be disambiguated >by qualification with their type names - which do not exist in this >case." I have looked in the Dept. of Defense Reference Manual, and it >appears that Moffat may not be right. As I (and a lecturer I consulted) >interpret the manual, the context that a constant, such as 'up', is >used in should determine which declaration is the correct one to use. >For example, > > semaphore := up; > > - it is clear from the context that the second declaration is the correct >one to use. Hence, no ambiguity exists. >Is this the correct interpretation, or is Moffat in the right here? There are several problems here, mainly stemming from the fact that you're reading a 1981 paper. The example is not valid Ada 83, because anonymous enumeration types are not allowed. My guess is that Moffat was writing his article based on the first, unofficial, Ada and that Ada al- lowed anonymous enumeration types. However, I have a copy of the July 1980 LRM and even there anonymous enumeration types appear illegal on a quick scan. Be that as it may, if you correct the example (for instance): TYPE flag_direction IS (up, down); TYPE semaphore_direction IS (up, down); flag : flag_direction; semaphore : semaphore_direction; then semaphore := up is indeed one of the contexts that an Ada compiler must be able to handle. (Note that the two type declarations define two different ups and downs.) Another problem is Moffat's statement that "'semaphore' may have been defined in the same ... scope." In Pascal that wouldn't fly, because an enumeration type declaration declares its literals and overloading is not allowed in Pascal. Charlie