comp.lang.ada
 help / color / mirror / Atom feed
* Default expression only allowed for "in" parameters - why?
@ 2001-04-06 20:41 Smark
  2001-04-06 21:30 ` Corey Ashford
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Smark @ 2001-04-06 20:41 UTC (permalink / raw)


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?

TIA,
Mark





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Corey Ashford @ 2001-04-06 21:30 UTC (permalink / raw)


My guess on this is that the default value would be something only
the implementation would care about, not the specification of the function,
nor the user of the function.  It does the user no good to know what the
default value is, because he has no way of knowing whether the implementation
will use that value or some other value.

In other words, it's an implementation detail best left hidden in the
implementation.

One could make the argument that the body of the function could have
a default output value while the spec wouldn't.  But this would break the
rule that the body's parameter profile must exactly match the spec's profile;
and I don't think this is a sufficient reason to break that rule, especially
when there is an alternative that's plenty adequate - move the assignment
to the beginning of the body.

- Corey

"Smark" <not.provided@all.com> wrote in message news:9al9mc$jgk2@cui1.lmms.lmco.com...
> 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?
>
> TIA,
> Mark
>





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  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 15:08   ` Smark
  2001-04-07 14:12 ` Charles H. Sampson
  2001-04-09 14:07 ` Marin David Condic
  3 siblings, 2 replies; 10+ messages in thread
From: Robert A Duff @ 2001-04-06 21:49 UTC (permalink / raw)


"Smark" <not.provided@all.com> writes:

> 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 defaults were allowed for 'out' params, I would think it ought to
mean that this is the default variable to pass to the parameter, not a
default initial value for it.  In Ada, a default applies if the
parameter is not explicitly given at the call site.  Are you saying that
Status should be initialized to OK if the actual parameter is specified?

Defaults for 'out' params were allowed in Green.  I don't know why they
were removed.  Perhaps the fact the you and I disagree on what they
ought to mean is a hint.

- Bob



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Ben Brosgol @ 2001-04-07  4:19 UTC (permalink / raw)


Robert A Duff <bobduff@world.std.com> wrote in message
news:wccvgohvgv7.fsf@world.std.com...
> "Smark" <not.provided@all.com> writes:
>
> > 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 defaults were allowed for 'out' params, I would think it ought to
> mean that this is the default variable to pass to the parameter, not a
> default initial value for it.

I agree with Bob.

> In Ada, a default applies if the
> parameter is not explicitly given at the call site.  Are you saying that
> Status should be initialized to OK if the actual parameter is specified?
>
> Defaults for 'out' params were allowed in Green.  I don't know why they
> were removed.  Perhaps the fact the you and I disagree on what they
> ought to mean is a hint.

If memory serves, the reason for the absence of defaults for 'out' and 'in
out' parameters was methodological.  A variable is passed as an [in] out
parameter in order to be modified, and the design team felt that this effect
should be explicit at the point of call, by the explicit presence of an
actual parameter.  In any event the capability (of default [in] out objects)
would probably not be too useful, since the default would need to be an
object visible at the procedure declaration whereas it is more typical for
an actual to be local to the scope in which the procedure is called.

Ben Brosgol
Ada Core Technologies
brosgol@gnat.com






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  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 14:12 ` Charles H. Sampson
  2001-04-07 18:17   ` Ben Brosgol
  2001-04-09 14:07 ` Marin David Condic
  3 siblings, 1 reply; 10+ messages in thread
From: Charles H. Sampson @ 2001-04-07 14:12 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  2001-04-07 14:12 ` Charles H. Sampson
@ 2001-04-07 18:17   ` Ben Brosgol
  0 siblings, 0 replies; 10+ messages in thread
From: Ben Brosgol @ 2001-04-07 18:17 UTC (permalink / raw)


Charlie Sampson 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.

The conditional "If memory serves" was not an assertion of lack of memory,
it was just an acknowledgement that, 20 years after the decision was made, I
do not want to make an unequivocal claim to recall all the details :-)  But
I do think that (as mentioned in my recent posting) the rationale was due to
methodological considerations and not implementation issues or other
factors.

> 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's arguable.  As Bob Duff mentioned, one interpretation of a default
initialization for an [in] out parameter would be the object that is passed
as actual parameter when none appears explicitly at the point of call.  I
believe that was the semantics that was considered in deciding whether to
include defaults for those modes.

> That difference alone is enough to make me happy with
> the decision to disallow "default values" for those modes.

Right, not enough gain for what would end up being a confusing feature.

>     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.)

More good reasons for excluding the feature.

Ben Brosgol
Ada Core Technologies
brosgol@gnat.com





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  2001-04-06 20:41 Default expression only allowed for "in" parameters - why? Smark
                   ` (2 preceding siblings ...)
  2001-04-07 14:12 ` Charles H. Sampson
@ 2001-04-09 14:07 ` Marin David Condic
  3 siblings, 0 replies; 10+ messages in thread
From: Marin David Condic @ 2001-04-09 14:07 UTC (permalink / raw)


The rationale AFAIK probably had to do with the fact that one could treat an
in parameter as a constant and provide constants or function calls as
actuals. With out or in-out, you've got to provide a variable so there
seemed to be less justification for default values.

IMHO, since you can define some kind of legitimate, predictable behavior for
in-out and out parameters with a default value, it probably should have been
done just for orthogonality. I've run into situations where it would have
been useful to have. There may be some technical reason for having left it
out, but offhand I can't think of one.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Smark" <not.provided@all.com> wrote in message
news:9al9mc$jgk2@cui1.lmms.lmco.com...
> 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?
>
> TIA,
> Mark
>
>





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  2001-04-07  4:19   ` Ben Brosgol
@ 2001-04-09 14:42     ` Marin David Condic
  0 siblings, 0 replies; 10+ messages in thread
From: Marin David Condic @ 2001-04-09 14:42 UTC (permalink / raw)


Just a thought: The use of defaults for in-out and out might be more of a
matter of interest at the call to the procedure rather than at the procedure
itself. With a default specified, the parameter could be ignored. If a
procedure passes back a status indication as an out parameter and the caller
doesn't care, the caller can ignore it because of the default. (O.K. it
looks a little funny - why does an initializer mean you can ignore the
parameter? Just because that's how you specify an ignorable parameter when
it is an in parameter.) Likewise, if the caller doesn't provide an in-out
parameter, one is created with the initial value assigned and then ignored
on return. The called procedure goes along fat, dumb and happy not knowing
that no actual was provided at the call.

I suppose there are other mechanisms possible for saying "this is an
ignorable parameter" but since Ada used a default assignment to an in
parameter to indicate this, I'd go with it for in-out and out as well. I've
seen a number of instances where I've wanted to have parameters to a
subprogram that the caller might sometimes want to use and might sometimes
choose to ignore. It would be useful to have such a mechanism and might make
Ada a little more C-ish {wash out my mouth with soap!} in terms of being
able to create subprograms with variable parameter lists.

The only reason I could think of for not doing this might be some argument
for safety. Is this the sort of thing that would be dangerous to include in
the language because of likely programmer errors that could not be detected?
I don't know that a case could be made for this, but maybe there is one. (If
it is error prone, then wouldn't the ignorable in parameters be likewise
dangerous?)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Ben Brosgol" <brosgol@world.std.com> wrote in message
news:GBEMM2.LoD@world.std.com...
> If memory serves, the reason for the absence of defaults for 'out' and 'in
> out' parameters was methodological.  A variable is passed as an [in] out
> parameter in order to be modified, and the design team felt that this
effect
> should be explicit at the point of call, by the explicit presence of an
> actual parameter.  In any event the capability (of default [in] out
objects)
> would probably not be too useful, since the default would need to be an
> object visible at the procedure declaration whereas it is more typical for
> an actual to be local to the scope in which the procedure is called.
>






^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  2001-04-06 21:49 ` Robert A Duff
  2001-04-07  4:19   ` Ben Brosgol
@ 2001-04-09 15:08   ` Smark
  2001-04-10 13:59     ` Martin Dowie
  1 sibling, 1 reply; 10+ messages in thread
From: Smark @ 2001-04-09 15:08 UTC (permalink / raw)


"Robert A Duff" <bobduff@world.std.com> wrote in message
news:wccvgohvgv7.fsf@world.std.com...
> "Smark" <not.provided@all.com> writes:
>
> > 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 defaults were allowed for 'out' params, I would think it ought to
> mean that this is the default variable to pass to the parameter, not a
> default initial value for it.  In Ada, a default applies if the
> parameter is not explicitly given at the call site.  Are you saying that
> Status should be initialized to OK if the actual parameter is specified?
>

First of all, thanks to everyone (Corey, Bob, Ben, and Charles, AFAICT),
for the excellent answers.  I seem to have had tunnel vision on this one
at the time.  I agree that the caller should not need to know anything
about how the procedure is implemented.

Yes, I was saying what you think I was saying.  The possibility of using
a default variable did not occur to me.  In fact this idea still seems
bizarre to me, although I can certainly think of cases where some out
parameters are "don't cares" to the caller.

> Defaults for 'out' params were allowed in Green.  I don't know why they
> were removed.  Perhaps the fact the you and I disagree on what they
> ought to mean is a hint.
>
> - Bob





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Default expression only allowed for "in" parameters - why?
  2001-04-09 15:08   ` Smark
@ 2001-04-10 13:59     ` Martin Dowie
  0 siblings, 0 replies; 10+ messages in thread
From: Martin Dowie @ 2001-04-10 13:59 UTC (permalink / raw)


> Yes, I was saying what you think I was saying.  The possibility of using
> a default variable did not occur to me.  In fact this idea still seems
> bizarre to me, although I can certainly think of cases where some out
> parameters are "don't cares" to the caller.

absolutely, just _please_ comment these occasions as such for
the poor maintenance sap how follows... :-)






^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-04-10 13:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2001-04-07 18:17   ` Ben Brosgol
2001-04-09 14:07 ` Marin David Condic

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