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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5ebeef2944e4167d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.85.98 with SMTP id g2mr1522284paz.37.1346453872708; Fri, 31 Aug 2012 15:57:52 -0700 (PDT) Received: by 10.68.232.230 with SMTP id tr6mr2152113pbc.16.1346453872693; Fri, 31 Aug 2012 15:57:52 -0700 (PDT) Path: a8ni4210pbd.1!nntp.google.com!4no1229341pbn.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 31 Aug 2012 15:57:52 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 References: <85mx1bwec4.fsf@stephe-leake.org> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: anonymous aggregates? From: Shark8 Injection-Date: Fri, 31 Aug 2012 22:57:52 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-08-31T15:57:52-07:00 List-Id: On Friday, August 31, 2012 4:37:58 PM UTC-6, Randy Brukardt wrote: > "Stephen Leake" wrote in message=20 >=20 > news:85mx1bwec4.fsf@stephe-leake.org... > ... >=20 > > If we introduce the notion of "anonymous aggregates" (styled after > > "anonymous arrays"), we could do this: >=20 > I'd be more likely to call this idea an "anonymous record" as that is the= =20 > obvious counterpart to "anonymous array". > declare >=20 > function Foo return > record > A : Integer; > B : Float; > end record > is begin > return > (A =3D> 1, > B =3D> 2.0); > end Foo; >=20 >=20 > (As a side-benefit, there'd be less griping about not repeating the name = in=20 > a record declaration. ;-) >=20 > I suspect that this was not done originally in Ada mainly because of=20 > concerns about arbitrarily introducing additional identifiers in the midd= le=20 > of other declarations. Not sure that's a real problem; there might be som= e=20 > weird visibility issues that arose. The thing I see is that if you needed to do something moderately complicate= d, where a extended-return must be used... There's nothing that lets you do= this, to my knowledge, in the language, so we would need a 'TYPE attribute= that would return out the given object's type. (We already got the 'Return= in Ada 2012 so we could use it in post-conditions.) Then we could have: SubType Initializing_Info is Boolean; -- To be changed for later/complex it= ems. Function Testing( Init : Initializing_Info ) Return record A : Integer; B : Float; end record is begin return Result : Testing'Return'Type:=3D (A =3D> 1, B =3D> 2.0) do if Init then A :=3D 23; end if; end return; end Testing; There have been a few times I've come across where being able to use the ty= pe like that would be advantageous... but no interesting specific example i= s coming to mind, but with discretes you could make 'Img a bit portable by = writing Discrete_var'Type'Image( Discrete_var ) -- A bit wordy, but it woul= d be quite portable in this case and a renames might make that a bit more f= riendly -- and using streams would be a bit easier if you have things funct= ional but want to use streams and just fiddle with your record components: Field_Name'Type'Write( [...] );