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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.82.5 with SMTP id g5mr4794196iob.101.1520875964820; Mon, 12 Mar 2018 10:32:44 -0700 (PDT) X-Received: by 10.157.96.5 with SMTP id h5mr503794otj.14.1520875964507; Mon, 12 Mar 2018 10:32:44 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!r195no1332933itc.0!news-out.google.com!h73-v6ni484itb.0!nntp.google.com!e10-v6no1328606itf.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 12 Mar 2018 10:32:44 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.218.37.33; posting-account=W2gdXQoAAADxIuhBWhPFjUps3wUp4RhQ NNTP-Posting-Host: 76.218.37.33 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4cf2a76e-626d-4ead-ae8a-dccdef41b283@googlegroups.com> Subject: anonymous records as tuples From: Stephen Leake Injection-Date: Mon, 12 Mar 2018 17:32:44 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3689 X-Received-Body-CRC: 3786011970 Xref: reader02.eternal-september.org comp.lang.ada:50939 Date: 2018-03-12T10:32:44-07:00 List-Id: I recently had to change a function that returned a single integer into a p= rocedure that returns two. So my code when from something like: Next_Shared_Token :=3D Next_Shared_Token - Tree.Count_Terminals (Index); to: declare Real : Integer; Virtual : Integer; begin Tree.Count_Terminals (Index, Real, Virtual); if Virtual =3D 0 then Next_Shared_Token :=3D Next_Shared_Token - Real; end if; end; This bothers me mainly because the variables Real, Virtual are not initiali= zed, and not declared constant, when clearly they should be. Some other languages handle a similar situation with tuples. For example, i= n Lua (https://www.lua.org/manual/5.3/manual.html#3.33) this would be: Real, Virtual =3D Tree.Count_Terminals (Tree_Index); We could do something similar in Ada with an "anonymous record": declare constant record Real : Integer; Virtual : Integer; end record :=3D Tree.Count_Terminals (Index); begin=20 if Virtual =3D 0 then Next_Shared_Token :=3D Next_Shared_Token - Real; end if; end; Perhaps the 'constant' should appear on each component instead; then some c= ould be not constant. Count_Terminals would be declared to return an anonymous record: function Count_Terminals (Tree : in out Tree_Type; Index : in Index_Type) return record=20 Real : Integer; Virtual : Integer; end record; The body of Count_Terminals would return a record aggregate for the result. Allowing anonymous records in other contexts could easily get messy. For ex= ample, there could be a larger record containing Real, Virtual: type Record_1 is record A : Float; Real : Integer; Virtual : Integer; B : Float; end record; Then an aggregate for that could be: (A =3D> 1.0,=20 record Real, Virtual end record =3D> Tree.Count_Terminals (I),=20 B =3D> 2.0) Alternately, the function result could be implicitly deconstructed: (1.0, Count_Terminals (I), 2.0) Or we could require Record_1 to contain an anonymous record: type Record_1 is record A : Float; record Real : Integer; Virtual : Integer; end record; B : Float; end record; I have no idea how complicated this would be for compiler implementors. I searched the Ada Issues database (http://ada-auth.org/search-ai12s.html) = for "anonymous record"; it occurs once (http://www.ada-auth.org/sresult.cgi= ?Search=3D23&Index=3D21&File=3D292&Seq=3D1), where Bob Duff complains that = Ada has anonymous arrays but not anonymous records. "tuples" appears many times, mostly in discussions, never in an actual prop= osal. -- Stephe