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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: anonymous records as tuples Date: Mon, 12 Mar 2018 19:01:24 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <4cf2a76e-626d-4ead-ae8a-dccdef41b283@googlegroups.com> NNTP-Posting-Host: 1aPdsouGBkizSj5ZSDumjw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.3 Xref: reader02.eternal-september.org comp.lang.ada:50940 Date: 2018-03-12T19:01:24+01:00 List-Id: On 2018-03-12 18:32, Stephen Leake wrote: > We could do something similar in Ada with an "anonymous record": > > declare > constant record > Real : Integer; > Virtual : Integer; > end record := Tree.Count_Terminals (Index); > begin > if Virtual = 0 then > Next_Shared_Token := Next_Shared_Token - Real; > end if; > end; > > Perhaps the 'constant' should appear on each component instead; then some could be not constant. By analogy to anonymous arrays: Temp : constant record Real : Integer; Virtual : Integer; end record := Tree.Count_Terminals (Index); > Count_Terminals would be declared to return an anonymous record: > function Count_Terminals (Tree : in out Tree_Type; Index : in Index_Type) > return record > Real : Integer; > Virtual : Integer; > end record; This has no analogy yet. If anonymous records were allowed, so must be arrays: function Read return array (Positive range <>) of Character; BTW, this and anonymous record parameters are analogous [polymorphism] to abstract array/record interface. You return a "class-wide" type which matches any concrete type (instance) with the same structure. I prefer explicit classes to by-structure anonymous types as more organized and controlled way to handle what is in the class and what is not. > The body of Count_Terminals would return a record aggregate for the result. > > Allowing anonymous records in other contexts could easily get messy. It requires matching by-structure, which is always messy. > Or we could require Record_1 to contain an anonymous record: > > type Record_1 is record > A : Float; > record ^^^^ C : record Anonymous record type /= anonymous object/component. > 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=23&Index=21&File=292&Seq=1), where Bob Duff complains that Ada has anonymous arrays but not anonymous records. > > "tuples" appears many times, mostly in discussions, never in an actual proposal. Tuples are bit more than just anonymous record types. Tuples also require a method of flattening an aggregate or list of arguments/results and promotion to a record. For example when you want pass a record and then pass it down to a subprogram as an argument list. Or when you want to declare all elements of the result tuple. So that instead of writing this: declare : record Real : Integer; Virtual : Integer; end record := Count_Terminals (Tree, Index); Real : Integer renames .Real; Virtual : Integer renames .Virtual; You will do: declare <> : Count_Terminals (Tree, Index); -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de