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,72c34c66b38e0e05 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-03 12:51:54 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!uunet!sea.uu.net!sac.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Proposal: Constructors, Assignment [LONG] User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Fri, 3 Jan 2003 20:50:51 GMT Content-Type: text/plain; charset=us-ascii References: > 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 " := X; return;". Also, I find myself declaring a "Result" object anyway, quite often. It would be convenient to get it for free. - Bob