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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cb68a222818235ed X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 11 Jun 2004 23:01:27 -0500 Date: Sat, 12 Jun 2004 00:01:27 -0400 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Renaming of enumeration constant References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <3c2dne2BD4WFHVfd4p2dnA@comcast.com> NNTP-Posting-Host: 24.147.90.114 X-Trace: sv3-3y6WwVnzD1UDOKB/v20C6LoCPpH5OKb004Ir+EEOnhxG25UoAyi2iOjgSvUCfmIjRNTjT6SAFWKBWCk!9uAhyzi+pRTYrIjHcgid8eM9IzLLKQM6iF0Cic8yDtLkOFhrlrr7bDTYxDInjg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: g2news1.google.com comp.lang.ada:1415 Date: 2004-06-12T00:01:27-04:00 List-Id: Xenos wrote: > Just a curiosity question: > > What is the difference (advantages, etc.) of defining a function rename for > an enumeration constant over just creating a constant. Consider: > > package X is > type E is (A, B, C); > end X; > > with X; > package Y is > function A return X.E renames X.A; > end Y; > > with X; > package Z is > A : constant X.E := X.A; > end Z; > > Is the "A" in Y treated any different than the "A" in Z by the compiler, or > will both achieve the same results. Is one considered "better" (whatever > that means) than the other? The difference is that a function will overload other functions and procedures of the same name, while a constant will hide such names in the local scope, and prevent them from being use visible. So if you have two packages that declare function A, and use clauses for both packages you can call either, unless the call is ambiguous. If you have two packages that declare constants A, and use clauses for both, you will still have to use a qualified name to reference A. A different advantage to using functions instead of constants is that you can do the renaming in the body of the package: package Foo is function A return Bar; ... package body Foo is function A renames... I'll let you read about the joys and issues of renaming as body. But if the value may change during development, this is the form you want. The advantage of the constant form is when you want it to be static. For example: Pi: constant := 3.14159_26...; (If the value of Pi changes the need to modify your program is a minor detail.) -- Robert I. Eachus The ideology he opposed throughout his political life insisted that history was moved by impersonal tides and unalterable fates. Ronald Reagan believed instead in the courage and triumph of free men and we believe it all the more because we saw that courage in him. -- George W. Bush June 11, 2004