From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: anonymous aggregates?
Date: Fri, 31 Aug 2012 06:22:35 -0400
Date: 2012-08-31T06:22:35-04:00 [thread overview]
Message-ID: <85mx1bwec4.fsf@stephe-leake.org> (raw)
Occasionally I have the following pattern:
declare
A : Integer;
B : Float;
procedure Foo (A : out Integer; B : out Float);
begin
Foo (A, B);
...
end;
where Foo initializes A, B.
In general, I prefer to initialize variables in the declaration, and
declare them constant if possible. But I can't do that here.
One option in current Ada is to declare a record type;
declare
type Foo_Return_Type is record
A : Integer;
B : Float;
end record;
function Foo return Foo_Return_Type is
begin
return
(A => 1,
B => 2.0);
end Foo;
A_B : constant Foo_Return_Type := Foo;
begin
...
end;
But that seems like overkill, especially since the code in "..." must be
edited; all references to A must be replaced by A_B.A.
If we introduce the notion of "anonymous aggregates" (styled after
"anonymous arrays"), we could do this:
declare
function Foo return
(A : Integer;
B : Float)
is begin
return
(A => 1,
B => 2.0);
end Foo;
(A : constant integer,
B : constant Float) := Foo;
begin
...
end;
I haven't thought much about how this would be implemented.
--
-- Stephe
next reply other threads:[~2012-09-07 1:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-31 10:22 Stephen Leake [this message]
2012-08-31 11:06 ` anonymous aggregates? Brian Drummond
2012-08-31 12:02 ` Dmitry A. Kazakov
2012-08-31 15:15 ` Adam Beneschan
2012-08-31 22:37 ` Randy Brukardt
2012-08-31 22:57 ` Shark8
2012-09-01 9:57 ` Georg Bauhaus
2012-09-02 11:25 ` Stephen Leake
2012-09-02 12:34 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox