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=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail From: anon@att.net Newsgroups: comp.lang.ada Subject: Re: Functions vs constants Date: Thu, 24 Jul 2014 12:26:21 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: Reply-To: anon@att.net NNTP-Posting-Host: iJsCDDCj70Z70XLlisHv9Q.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: IBM NewsReader/2 2.0 Xref: number.nntp.dca.giganews.com comp.lang.ada:187830 Date: 2014-07-24T12:26:21+00:00 List-Id: It the definition "Constants" From RM 3.3 (13). "The value of a constant object cannot be changed between its initialization and its finalization," while overloading might lead to ambiguity which violate Ada rules. At the same Constants are more likey to be static while only a set number of functions type can every be static, RM 4.9 ( 18 => ( 19 .. 22 ) ). Now, function overloading just allow one to use the same name with different aspect to resolute which actual function routine to use. But for some constant object there is no aspect to allow overloading to resolute the actual value. An example: -- Base Type type Limited_Integer is range .. ; -- Limited_Integer Five : constant := 5 ; -- universal integer Five : constant Short_Integer := 2 ; -- Short_Integer Five : constant Float := 8.0 ; -- Float Five : constant := 3.33 ; -- universal float -- Ambiguous expressions: -- which is the current value the universal integer ( 5 ) -- or the Short_Integer ( 2 ) X : Limited_Integer := Limited_Integer ( Five ) ; -- This should choose the universal integer but the type -- and value may be hidden because of overloading. Y : Limited_Integer := Five ; even though the base type is different in each constant object the use does not allow the system to fully choose which value should be used in the variable statements. And if the constant objects are defined in different packages the compiler normally hides the visibility of all package. To limit the ambiguous expressions. So, how would you define an overloading constant objects that would not lead to an ambiguous expressions? In , Victor Porton writes: >Isn't the following a mis-design of Ada? > >Constants in a good programming language should be equivalent to argument- >less functions which return these constants. > >However, in Ada functions can be overloaded by their return type, while >constants cannot. > >Mad idea, but I propose it: Make in a future specification of Ada constants >overloadable (moreover, make constants argument-less functions). (However I >am not sure how this could affect reliability. But should we think about it >at all? After all function overloading was not ruled out with the same >requirements, and ruling this out as possibly unreliable would be a half- >measure.) > >I wrote this post after a practical problem whether I should use a String >constant or a function returning String to return the library version >(related with a C library for which I am writing bindings). There are no >definite answer to this question. It is in any case of wrong design. > >-- >Victor Porton - http://portonvictor.org