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-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!b25g2000prb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Hiding the value of Constants Date: Tue, 7 Jul 2009 08:51:35 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0549aae1-d200-4c81-aa92-8d18df6cf0d4@b25g2000prb.googlegroups.com> References: <30696d63-16e8-44e2-a4a5-db5095d7cfec@m3g2000pri.googlegroups.com> <4a531837$0$30227$9b4e6d93@newsspool1.arcor-online.net> <5b49f256-f779-4030-a50d-5f31fd08ddff@26g2000yqk.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1246981897 11105 127.0.0.1 (7 Jul 2009 15:51:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 7 Jul 2009 15:51:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b25g2000prb.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6883 Date: 2009-07-07T08:51:35-07:00 List-Id: On Jul 7, 3:41=A0am, Hibou57 (Yannick Duch=EAne) wrote: > As some one are talking about Funny_Types, here is a funny thing > (thinking about it when I saw this solution) : Ada defines enumeration > contants as parameterless functions (just like you propose for these > constants). > > RM 2005 3.5.1 says: > > > 6 {enumeration literal} Each enumeration_literal_specification is the > > explicit declaration of the corresponding enumeration literal: it > > declares a parameterless function, whose defining name is the > > defining_identifier or defining_character_literal, and whose result > > type is the enumeration type. > > But this is with some restrictions (ex. one may not get the adress of > such a function) > > This has some conscequences on the name resolution of an enumeration > literal reference vs of a constant reference. Sometimes I wish both > will be one day handled the same (enumeration literals and constants I believe the reason enumeration literals are actually functions is so that you can use the same enumeration literal in more than one enumeration type and not have to worry about name conflicts. The overloading rules will allow the compiler to figure out which one is meant. There are additional bonuses, such as being able to use an enumeration literal as the actual for a generic instantiation that expects a function. How useful that is in practice, I don't know. I'm not sure why you would want enumeration literals to be treated like constants, though. I don't know of any advantage to making them officially "constants"; that is, I can't think of any language rule off the top of my head where a constant would be allowed but a static function such as an enumeration literal couldn't. In effect, I believe you can use them anywhere a constant could be used, and in some places where constants can't. If you mean that you'd like constants to be treated like static functions, so that you can overload them: Max : constant Integer :=3D 15; Max : constant Float :=3D 15.0; that's an intriguing idea. Not intriguing enough for me to have to make all the necessary changes to our compiler, but intriguing nonetheless.... -- Adam