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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cced0e2ac94722f3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.204.156.205 with SMTP id y13mr342663bkw.3.1325855683659; Fri, 06 Jan 2012 05:14:43 -0800 (PST) Path: cj8ni59148bkb.0!nntp.google.com!news2.google.com!goblin3!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada2012 : Expression functions and extended return statements Date: Fri, 6 Jan 2012 14:13:01 +0100 Organization: cbb software GmbH Message-ID: References: <26f343ea-d694-4089-b594-f32b471db3a4@m4g2000vbc.googlegroups.com> <94808f24-938b-476e-8912-f98b52982d53@j10g2000vbe.googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Date: 2012-01-06T14:13:01+01:00 List-Id: On Fri, 6 Jan 2012 03:37:27 -0800 (PST), Martin wrote: > On Jan 6, 11:23�am, "Peter C. Chapin" wrote: >> On 2012-01-06 05:02, Martin wrote: >> >>> I still think it would be nice to have a short-hand e.g. 'return >>> Result :<> �do'. If anything it would then draw the eye to the more >>> interesting case when the 2 are different. >> >> You need to repeat the type for ordinary returns as well. >> >> function F return Integer is >> � �Result : Integer; �-- Duplication of return type here. >> begin >> � �Result := 1; >> � �return Result; >> end F; >> >> To be consistent it seems like you'd need to be able to use '<>' >> throughout the body of the function. >> >> function F return Integer is >> � �Result : <>; �-- Shorthand for function's return type. >> begin >> � �Result := 1; >> � �return Result; >> end F; >> >> Considering Ada's tendency to require one to repeat information in >> earlier declarations, this seems a bit unAda-like to me. Also this would >> allow '<>' to show up in a lot of strange looking places such as type >> conversions and type qualifications. >> > The difference is that the declaration of 'Return' in the extended > return is that the compiler 'knows' that this is the declaration of > something that's going to be returned - it can't know that in the > ordinary return case. This is not a declaration, because the result is not an object. Note that your argument applies to other parameters of a subprogram: procedure Foo (X : Integer); -- Declares X procedure Foo (X : Integer) is -- Reiterates what is already known ... end Foo; > It would certainly be a departure from current Ada - adding a little > bit of "Type Inferencing" to the language. But I'm not adverse to > that...so long as the inferencing is safe. I like SML/NJ :-) Maybe. There are lots of cases where repetition is boring and error prone. E.g.: if X in T'Class then declare XX : T'Class renames T'Class (X); or if X /= null then declare XX : T renames X.all; or X : Subarray renames Array_Thing; -- Legal, but broken As for return, the second best (the first one is to ditch return statement altogether) would be: X : return -- Loop label syntax ... end X; BTW, Ada could have the result explicitly named like other parameters are. E.g. function F return X : Integer := 1 is begin if Something then X := 2; end if; end F; -- No explicit return needed, obviously -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de