From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cea502f7b2820a37 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Enumeration literals and their associated functions Date: 20 Oct 2005 18:59:06 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1129849146 10204 192.74.137.71 (20 Oct 2005 22:59:06 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 20 Oct 2005 22:59:06 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:5836 Date: 2005-10-20T18:59:06-04:00 List-Id: "Randy Brukardt" 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