comp.lang.ada
 help / color / mirror / Atom feed
* Question on enumeration types
@ 1991-07-30 12:35 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!waikato.ac.nz!comp.vu
  0 siblings, 0 replies; 2+ messages in thread
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!waikato.ac.nz!comp.vu @ 1991-07-30 12:35 UTC (permalink / raw)


In an article I'm currently reading [David Moffat; "Enumerations in Pascal, Ada
, and Beyond"; from: SIGPLAN 16.2 1981 pp77-82] there is an example which invol
ves 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 occurren
ces 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 co
nstant, such as 'up', is used in should determine which declaration is the corr
ect 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?

Thanks,
Ray [%-)
-- 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~ \"""/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~  0 0  ~~~~~~~~~~~~ rjm@cosc.canterbury.ac.nz ~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~  v  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~  "  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question on enumeration types
@ 1991-07-31 23:46 Charles H. Sampson
  0 siblings, 0 replies; 2+ messages in thread
From: Charles H. Sampson @ 1991-07-31 23:46 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1991-07-31 23:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-07-30 12:35 Question on enumeration types cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wupost!waikato.ac.nz!comp.vu
  -- strict thread matches above, loose matches on Subject: below --
1991-07-31 23:46 Charles H. Sampson

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