comp.lang.ada
 help / color / mirror / Atom feed
* anonymous aggregates?
@ 2012-08-31 10:22 Stephen Leake
  2012-08-31 11:06 ` Brian Drummond
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Stephen Leake @ 2012-08-31 10:22 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-09-09  6:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-31 10:22 anonymous aggregates? Stephen Leake
2012-08-31 11:06 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox