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-Thread: 103376,cced0e2ac94722f3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.10.149 with SMTP id p21mr356764bkp.1.1325861123180; Fri, 06 Jan 2012 06:45:23 -0800 (PST) Path: cj8ni59703bkb.0!nntp.google.com!news1.google.com!news.glorb.com!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 06 Jan 2012 08:45:22 -0600 User-Agent: NewsTap/3.5.1 (iPad) From: Martin Dowie Newsgroups: comp.lang.ada Mime-Version: 1.0 Message-ID: <1650969959347553100.869853martin-re.mo.ve.thedowies.com@news.btinternet.com> Subject: Re: Ada2012 : Expression functions and extended return statements References: <94808f24-938b-476e-8912-f98b52982d53@j10g2000vbe.googlegroups.com> Date: Fri, 06 Jan 2012 08:45:22 -0600 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-xVlgnysc0xlc1jFYcXBh6rKMdpbfKQfMlsdFhbWN6tQn6TGDpmQBD2va38mDObNfve09QUIDDT/l3PF!el1xbapusWAuZXrahSG5eY7FRp4U6931Xq2oylTSDkCPsMnJFPD+CvfMHZZeGs3+JBGwzQHrouMu!6R8E2Qw5B+LtYXYRqiHui7mHB+5sUWFck9VsdaMWhA/7Wksa X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4781 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2012-01-06T08:45:22-06:00 List-Id: "Dmitry A. Kazakov" wrote: > 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. 2012 RM 3.1 6/3 says it is a declaration (but I should have written 'Result' not 'Return'). > > 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; Yes but here you may not have a procedure declaration and even if you did, they need not be close or even in the same. The chances of a extended return statement not being close to the 'return ... Is' seems remote. >> 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 A bit like Pascal(?), didn't use the function's name at the point of return?...so for function 'Foo' you wrote something like, Foo := 100; ? The evolution of Ada has always resulted in adding things that aren't "Ada-like" when compared to the previous revision. There was a paper around at one time with a proposal to add implicit generic instantiation to the language... -- Martin -- -- Sent from my iPad