comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Enumeration literals and their associated functions
Date: 20 Oct 2005 18:59:06 -0400
Date: 2005-10-20T18:59:06-04:00	[thread overview]
Message-ID: <wcczmp36bid.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: voKdneIMJ79WicXeRVn-hg@megapath.net

"Randy Brukardt" <randy@rrsoftware.com> writes:

> 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);

I thought the classic example was Rainbow_Color and Traffic_Light,
both of which have a Red.  ;-)

> 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.

Yeah, that's probably the reason.  The reasoning seems to be:

1. Only subprograms should be overloadable.
2. But it would sure be nice if enumeration literals were overloadable.
3. Therefore, we had better pretend that enum lits are functions.

It seems to me it would be better, after recognizing (2), to say:

3. Therefore, (1) must be wrong.  It should be replaced by "Only
   subprograms and enumeration literals should be overloadable."

Pretending enum lits are functions is just plain confusing,
and provides no important functionality.

And, perhaps:

4. If enum lits are overloadable, then constants should be overloadable,
   too.

After all, one might want to change type Base above (for various good
reasons) to:

    package ... is
        type Base is private;
        Bin: constant Base;
        Oct: constant Base;
        ...
    private
        ...
    end ...;

But now any place that uses both Base and Month might become ambiguous,
and have to be changed, for no good reason.

> 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.

More consistent, perhaps.  Certainly not simpler.

- Bob



  reply	other threads:[~2005-10-20 22:59 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
2005-10-20 22:59     ` Robert A Duff [this message]
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