comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Proposal: Constructors, Assignment [LONG]
Date: Sat, 04 Jan 2003 13:53:04 +0100
Date: 2003-01-04T13:53:04+01:00	[thread overview]
Message-ID: <av6lei$cc2dv$1@ID-77047.news.dfncis.de> (raw)
In-Reply-To: wccisx6vtxw.fsf@shell01.TheWorld.com

Robert A Duff wrote:

>> Dmitry A. Kazakov wrote in message ...
> 
>> >function Make_Session (Count: Integer) return Internet_Session is
>> >begin
>> >   for Index in Integer'Range loop
>> >      declare
>> >         Result : return Internet_Session (Index);
>> >      begin
>> >         if HALT (x) then
>> >            return Result;
>> >         end if;
>> >      end;
>> >   end loop;
>> >end Make_Session;
> 
> There were various rules, such as disallowing the "return object" in a
> nested block.  I don't remember what they all were.  Look at the AI
> and/or ARG minutes if you care.
>
> The idea is basically just like in Pascal, where there's a special
> return object, conceptually declared as a local of the function.

We will have numerous problems with combining variable-sized objects and 
by-reference parameter passing. This only would add unnecessary complexity 
to the language. It also would raise a question, why OUT parameters of 
procedures and entry points cannot act this way.

> To specify what to return, assign into this special object.
> Or, if limited, *initialize* this object.

The problem is to ensure that this would happen exactly once, for *some* of 
result types.

> Various syntaxes were discussed for defining the special object --
> including allowing it to be implicitly declared and/or denoting it via
> an attribute.
> 
> Pascal uses the name of the function to denote this special object.
> That's a bad idea, because it's ambiguous with a function call
> of zero parameters.
> 
> IMHO, having a special object is better than the traditional Ada way (a
> return statement), and I wish the language had used this mechanism in
> the first place.  This is because a return statement causes a transfer
> of control.

But exactly this ensures that you cannot do it twice.

> It's not quite as bad as a goto, but it seems to me that
> one should not be required to do a jump when it's not needed.  The usual
> (and easiest to understand) case is when the "return" is actually at the
> end of execution anyway, and no jump is needed.  When a jump-to-end *is*
> needed, that case should look "special" in the code.  Combining "set
> result" with "jump to end" is a bad idea.

I disagree. IMO it is the basic idea of a subroutine having a result. If you 
want to separate "set" and "return", there are procedures for this.

> At least, it's a bad idea if you're forced to use it.  I wouldn't mind
> making "return X" be a shorthand for "<result obj> := X; return;".

But in a comparable case:

"X := Y;" is a shorthand for "Finalize (X); Copy_constructor (X, Y);"

the decision made is directly opposite!

> Also, I find myself declaring a "Result" object anyway, quite often.
> It would be convenient to get it for free.

-- 
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-01-04 12:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-24 11:16 Proposal: Constructors, Assignment [LONG] Dmitry A. Kazakov
2002-12-26 22:11 ` Nick Roberts
2002-12-27 17:43   ` Dmitry A. Kazakov
2002-12-27 20:17     ` Randy Brukardt
2002-12-29 13:43       ` Dmitry A. Kazakov
2002-12-29 18:45         ` Nick Roberts
2002-12-30 12:23           ` Dmitry A. Kazakov
2002-12-30 15:14             ` Robert A Duff
2002-12-31 13:02               ` Dmitry A. Kazakov
2003-01-01  0:28                 ` Randy Brukardt
2003-01-01 14:13                   ` Dmitry A. Kazakov
2003-01-02 19:44                     ` Randy Brukardt
2003-01-03 13:21                       ` Dmitry A. Kazakov
2003-01-03 19:29                         ` Randy Brukardt
2003-01-03 20:50                       ` Robert A Duff
2003-01-04 12:53                         ` Dmitry A. Kazakov [this message]
2003-01-01  0:54         ` Randy Brukardt
2003-01-01 14:13           ` Dmitry A. Kazakov
2003-01-02 19:36             ` Randy Brukardt
2003-01-03 13:20               ` Dmitry A. Kazakov
replies disabled

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