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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Functions vs constants Date: Wed, 23 Jul 2014 17:57:07 -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: pcls7.std.com 1406152595 4860 192.74.137.71 (23 Jul 2014 21:56:35 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 23 Jul 2014 21:56:35 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:DXVvsD9XOcxiRQHbGBwwCk2nWuQ= Xref: news.eternal-september.org comp.lang.ada:21166 Date: 2014-07-23T17:57:07-04:00 List-Id: 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. Those are equivalent in a pure functional language. Not in Ada. E.g. a constant initialized to "new T" always denotes the same heap object, whereas a function that says "return new T" returns a new object every time it's called. > However, in Ada functions can be overloaded by their return type, while > constants cannot. I agree. IMHO everything should be overloadable. For consistency, among other things. Confusion should be minimized, not by disallowing overloading of certain kinds of declarations, but by making the resolution rules "not too smart". That is, anything that is likely to confuse a programmer should be ambiguous, and therefore illegal, by the resolution rules. It really is odd that this allows overloading: type Color is (Red, Orange, Yellow); but this does not: type Color is range ...; Red: constant Color := 0; Orange: constant Color := 1; Yellow: constant Color := 2; And there should be no hiding. Jean Ichbiah had a brilliant idea about how use clauses should work (for overloadable declarations). He should have applied that to all visibility, not just use visibility. > Mad idea, but I propose it: Make in a future specification of Ada constants > overloadable... A good idea in 1980, but it can't happen now. For one thing, it's hard to see how to do that without breaking compatibility, as I think Randy pointed out. For another, it's just not badly broken enough to bother fixing at this point. And expression functions make this restriction somewhat less painful. >... (moreover, make constants argument-less functions). I don't see any reason to tie "is a subprogram" to "is overloadable". That's done for enumeration literals, but it's just plain weird, IMHO. - Bob