comp.lang.ada
 help / color / mirror / Atom feed
From: "Samuel T. Harris" <samuel_t_harris@Raytheon.com>
Subject: Re: HELP: renames and enum values
Date: 2000/04/13
Date: 2000-04-13T00:00:00+00:00	[thread overview]
Message-ID: <38F6323B.79B6A9F7@Raytheon.com> (raw)
In-Reply-To: 8d4t6r$oam$1@nnrp1.deja.com

Ted Dennison wrote:
> 
> In article <38F5D6F9.5B8892F2@bton.ac.uk>,
>   John English <je@bton.ac.uk> wrote:
> > Dale Stanbrough wrote:
> > > All i was attempting to say is that
> > >
> > >    type blah renames bleh;
> > >
> > > could be predicted to have the same semantics as a subtype
> > > declaration (this would be the "other way" of performing
> > > subtyping).
> > >
> > > I know what beginners think of, because I had 8 years of
> > > teaching beginners. This is something that some of them
> > > thought of (but not many because most of them were introduced
> > > to subtypes long before renames!).
> >
> > What's even less obvious is the way to rename enumeration literals:
> >
> >  function Enum_Literal return Enum_Type renames Other_Enum_Literal;
> >
> > Now, that *really* confuses them, and none of them would ever be
> > able to guess it without being told!
> 
> What's wrong with:
>    Enum_Literal : constant Enum_Type := Other_Enum_Literal;
> 

package a is
  type x is (one, two, three);
  type y is (one, two, three);
end a;

with a;
package b is
  function one return a.x renames a.one;
  function two return a.x renames a.two;
  function three return a.x renames a.three;

  function one return a.y renames a.one;
  function two return a.y renames a.two;
  function three return a.y renames a.three;
end b;

with a;
package c is
  one : constant a.x := a.one;
  two : constant a.x := a.two;
  three : constant a.x := a.three;

  one : constant a.y := a.one;      -- compilation error
  two : constant a.y := a.two;      -- compilation error
  three : constant a.y := a.three;  -- compilation error
  -- these are co-resident homographs.
end c;

As I alluded to in a previous post, enumeration literals
are semantically defined as parameter-less functions. This
allows overloading them in different enumeration type
definitions. This also them multiple renames because the
correct renaming is a parameter-less function renames
declaration. Constants cannot be overloaded!

However, constants usually fill the bill in my actual
experience since overloaded enumeration literals simply
don't come up often in those rare cases where I need
to redefine the things. I say rare cases because there
are many other ways to get the adequate results that I
simply don't need to rename enumeration literals anymore.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"




  reply	other threads:[~2000-04-13  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <38ECE0EB.4BD4A53E@mindspring.com>
2000-04-07  0:00 ` HELP: renames and enum values Samuel T. Harris
2000-04-07  0:00   ` Al Johnston
2000-04-09  0:00     ` Robert Dewar
2000-04-09  0:00       ` dale
2000-04-09  0:00         ` Robert Dewar
2000-04-10  0:00           ` Dale Stanbrough
2000-04-13  0:00             ` John English
2000-04-13  0:00               ` Ted Dennison
2000-04-13  0:00                 ` Samuel T. Harris [this message]
2000-04-13  0:00                 ` Robert A Duff
2000-04-13  0:00               ` Robert Dewar
2000-04-14  0:00                 ` John English
2000-04-13  0:00               ` Samuel T. Harris
2000-04-14  0:00               ` Tucker Taft
2000-04-10  0:00       ` Samuel T. Harris
2000-04-11  0:00       ` Al Johnston
2000-04-10  0:00     ` Samuel T. Harris
2000-04-11  0:00       ` Al Johnston
2000-04-11  0:00 ` Tucker Taft
replies disabled

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