comp.lang.ada
 help / color / mirror / Atom feed
From: sampson@cod.nosc.mil  (Charles H. Sampson)
Subject: Re: Question on enumeration types
Date: 31 Jul 91 23:46:43 GMT	[thread overview]
Message-ID: <3208@cod.NOSC.MIL> (raw)

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

             reply	other threads:[~1991-07-31 23:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-07-31 23:46 Charles H. Sampson [this message]
  -- strict thread matches above, loose matches on Subject: below --
1991-07-30 12:35 Question on enumeration types cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!waikato.ac.nz!comp.vu
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox