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-7-bit X-Google-Thread: 103376,9625801f07d834 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-07 07:14:01 PST Newsgroups: comp.lang.ada Subject: Re: Default expression only allowed for "in" parameters - why? From: claveman@inetworld.net (Charles H. Sampson) Date: Sat, 7 Apr 2001 07:12:01 -0700 Message-ID: <1erhfmz.1fh9c7hf1mhpuN%claveman@inetworld.net> References: <9al9mc$jgk2@cui1.lmms.lmco.com> User-Agent: MacSOUP/2.4.6 NNTP-Posting-Host: dialup1-1.inforumnet.com X-Original-NNTP-Posting-Host: dialup1-1.inforumnet.com X-Trace: 7 Apr 2001 07:11:38 -0700, dialup1-1.inforumnet.com Organization: CalWeb Internet Services Inc. Your affordable ISP. (3) X-Original-NNTP-Posting-Host: 127.0.0.1 Path: supernews.google.com!sn-xit-03!supernews.com!freenix!fr.clara.net!heighliner.fr.clara.net!news.tele.dk!207.173.6.98!calwebnntp!calwebnnrp!claveman Xref: supernews.google.com comp.lang.ada:6615 Date: 2001-04-07T07:12:01-07:00 List-Id: Smark wrote: > LRM 6.1(19): > A default_expression is only allowed in a parameter_specification > for a formal parameter of mode in. > > I recently had a situation in which it was desirable for me to have > a default value for an "out" parameter of a function. It was something > like: > > procedure Do_Something (Data : in Some_Type; > Status : out Status_Type); > > Normally, Status = Ok. It seemed to me that, rather than setting > Status := Ok at the beginning of my procedure, it would make sense to > just set the default value in the procedure spec. That is: > > procedure Do_Something (Data : in Some_Type; > Status : out Status_Type := Ok); > > It also seemed like a strange idea, because I never recalled seeing > it done. Sure enough, it is prohibited by the LRM. What is the > rationale for this? If Ben Brosgol can't remember why they were eliminated then there's probably a good chance that the reason is lost in the mists of time. Notice however that there's a significant difference of semantics be- tween default values for the three parameter modes. For "in" mode, "de- fault" means the value to be used when no value is specified (at the point of call), the same as for other cases where default values are de- fined. For "out" and "in out", what you're calling "default" would mean initial value. That difference alone is enough to make me happy with the decision to disallow "default values" for those modes. In addition, why should the user of the procedure care what initial value is assigned to the parameter (rephrasing what Corey Ashford said)? You would be advertising this implementation detail to the outside world. Furthermore, to keep other rules consistent, if you decided to change that facet of the implementation then all users of the procedure would have to be recompiled. (Actually, they wouldn't, but most compil- ers would force the recompiles.) Charlie -- To get my correct email address, replace the "claveman" by "csampson" in my fake (anti-spam) address.