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!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: anonymous records as tuples Date: Mon, 12 Mar 2018 18:59:32 -0500 Organization: JSA Research & Innovation Message-ID: References: <4cf2a76e-626d-4ead-ae8a-dccdef41b283@googlegroups.com> <2153155f-2778-421f-97cb-4d229fb9355b@googlegroups.com> <290ddbd1-3aa1-4238-8737-51d8090af7d3@googlegroups.com> Injection-Date: Mon, 12 Mar 2018 23:59:32 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="13229"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:50949 Date: 2018-03-12T18:59:32-05:00 List-Id: "Stephen Leake" wrote in message news:290ddbd1-3aa1-4238-8737-51d8090af7d3@googlegroups.com... > On Monday, March 12, 2018 at 2:17:08 PM UTC-5, Robert Eachus wrote: >> On Monday, March 12, 2018 at 1:32:46 PM UTC-4, Stephen Leake wrote: >> > I recently had to change a function that returned a single integer into >> > a procedure that returns two... >> >> What is wrong with something like: >> >> -- in Tree: >> >> type Return_Values is record >> Real : Integer; >> Virtual : Integer; >> end record; >> >> function Count_Terminals (Index...) return Return_Values; >> ... >> >> declare >> Returned: constant Tree.Return_Values := Tree.Count_Terminals(Index); >> Real: Integer renames Returned.Real; >> Virtual: Integer renames Returned.Virtual; >> begin >> if Virtual = 0 then >> Next_Shared_Token := Next_Shared_Token - Real; >> end if; >> end; > > That works, but is more verbose; I have to make up a name for the > result type, when it's really an anonymous tuple of values. But I > suspect the ARG would say the gain is not worth the cost. I know *I* would say that, and I'd go even further, and say anonymous types in general are a bad thing for Ada. Ada is designed around named types (where two objects are the same only if the underlying types come from the same declaration), while anonymous types pretty much have to be matched structurally (if two types define the same structure, then they are the same). There's nothing wrong with structural equivalence per-se, but mixing it with named equivalence tends to produce a hodge-podge of rules that mainly confuse everyone (implementers and users). And there are so many Ada constructs which assume a name is handy (type conversion, generic instantiation, and so on) that anonymous types tend to always have an incomplete set of capabilities. But I'm not the ARG (even if it sometimes appears that way), so others may feel differently. Randy.