comp.lang.ada
 help / color / mirror / Atom feed
From: claveman@inetworld.net (Charles H. Sampson)
Subject: Re: Default expression only allowed for "in" parameters - why?
Date: Sat, 7 Apr 2001 07:12:01 -0700
Date: 2001-04-07T07:12:01-07:00	[thread overview]
Message-ID: <1erhfmz.1fh9c7hf1mhpuN%claveman@inetworld.net> (raw)
In-Reply-To: 9al9mc$jgk2@cui1.lmms.lmco.com

Smark <not.provided@all.com> 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.



  parent reply	other threads:[~2001-04-07 14:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-06 20:41 Default expression only allowed for "in" parameters - why? Smark
2001-04-06 21:30 ` Corey Ashford
2001-04-06 21:49 ` Robert A Duff
2001-04-07  4:19   ` Ben Brosgol
2001-04-09 14:42     ` Marin David Condic
2001-04-09 15:08   ` Smark
2001-04-10 13:59     ` Martin Dowie
2001-04-07 14:12 ` Charles H. Sampson [this message]
2001-04-07 18:17   ` Ben Brosgol
2001-04-09 14:07 ` Marin David Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox