From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: anonymous records as tuples
Date: Mon, 12 Mar 2018 12:34:55 -0700 (PDT)
Date: 2018-03-12T12:34:55-07:00 [thread overview]
Message-ID: <290ddbd1-3aa1-4238-8737-51d8090af7d3@googlegroups.com> (raw)
In-Reply-To: <2153155f-2778-421f-97cb-4d229fb9355b@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.
> (And declaring Real as an Integer really rubs me wrong.)
This is for a parser; it's counting "real tokens" from the source text versus "virtual tokens" inserted by an error recovery process.
I ended up resolving it a different way; first I check if there are any virtual tokens, then I count real tokens.
-- Stephe
next prev parent reply other threads:[~2018-03-12 19:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-12 17:32 anonymous records as tuples Stephen Leake
2018-03-12 18:01 ` Dmitry A. Kazakov
2018-03-12 19:17 ` Robert Eachus
2018-03-12 19:34 ` Stephen Leake [this message]
2018-03-12 23:59 ` Randy Brukardt
2018-03-13 2:51 ` Dan'l Miller
2018-03-13 8:28 ` Dmitry A. Kazakov
2018-03-12 21:09 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox