comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Proposal: Constructors, Assignment [LONG]
Date: Fri, 3 Jan 2003 20:50:51 GMT
Date: 2003-01-03T20:50:51+00:00	[thread overview]
Message-ID: <wccisx6vtxw.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: v195k5bkq6d535@corp.supernews.com

> 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.
To specify what to return, assign into this special object.
Or, if limited, *initialize* this object.

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

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;".

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

- Bob



  parent reply	other threads:[~2003-01-03 20:50 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 [this message]
2003-01-04 12:53                         ` Dmitry A. Kazakov
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