From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Enumeration literals and their associated functions
Date: Thu, 20 Oct 2005 17:10:04 -0500
Date: 2005-10-20T17:10:04-05:00 [thread overview]
Message-ID: <voKdneIMJ79WicXeRVn-hg@megapath.net> (raw)
In-Reply-To: D6Q5f.3855$Yx5.800@reader1.news.jippii.net
"Niklas Holsti" <nobody@nowhere.fi> wrote in message
news:D6Q5f.3855$Yx5.800@reader1.news.jippii.net...
> Maciej Sobczak wrote:
> > Hi,
> >
> > <http://www.adaic.org/standards/95aarm/html/AA-3-5-1.html>, paragraph 6
> > states that for each enumeration literal specification there is an
> > appropriate parameterless function declated.
> >
> > type Color is (RED, GREEN, BLUE);
> >
> > ...
> > If instead "RED" above is considered to be a literal, then what's the
> > sense of having an associated function at all?
>
> I believe that the LRM defines enumeration literals as functions
> because this automatically defines their overloading. That is, you
> can have another enumeration type that also has the literal RED (a
> synonym), yet overloading lets the compiler resolve which RED is
> meant, by the context.
Right. The classic example is:
type Base is (Bin, Oct, Dec, Hex);
type Month is (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
Dec);
Both enumerations have literals Oct and Dec. If these were treated as
objects, that would be illegal. So the language treats them as intrinsic
functions instead. Then
This_Month : Month := Oct;
works, because the standard overloading rules apply.
Practically, you can just think of them as overloaded literals. It probably
makes more sense that way. The definition as a function is primarily to make
the language rules more consistent (and simpler); it's not some sort of
important feature.
Randy.
next prev parent reply other threads:[~2005-10-20 22:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-20 14:21 Enumeration literals and their associated functions Maciej Sobczak
2005-10-20 15:35 ` Frank J. Lhota
2005-10-20 19:26 ` Simon Wright
2005-10-20 16:17 ` Dmitry A. Kazakov
2005-10-20 17:03 ` Niklas Holsti
2005-10-20 22:10 ` Randy Brukardt [this message]
2005-10-20 22:59 ` Robert A Duff
2005-10-21 3:10 ` Larry Kilgallen
2005-10-21 4:57 ` Jeffrey R. Carter
2005-11-30 6:07 ` adaworks
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox