comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: anonymous aggregates?
Date: Fri, 31 Aug 2012 15:57:52 -0700 (PDT)
Date: 2012-08-31T15:57:52-07:00	[thread overview]
Message-ID: <a0bf4fce-3e1d-4bc2-a5d8-026dfbd151a9@googlegroups.com> (raw)
In-Reply-To: <k1rec3$68q$1@munin.nbi.dk>

On Friday, August 31, 2012 4:37:58 PM UTC-6, Randy Brukardt wrote:
> "Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message 
> 
> news:85mx1bwec4.fsf@stephe-leake.org...
> ...
> 
> > If we introduce the notion of "anonymous aggregates" (styled after
> > "anonymous arrays"), we could do this:
> 
> I'd be more likely to call this idea an "anonymous record" as that is the 
> obvious counterpart to "anonymous array".
> declare
> 
>     function Foo return
>        record
>           A : Integer;
>           B : Float;
>         end record
>     is begin
>         return
>             (A => 1,
>              B => 2.0);
>     end Foo;
> 
> 
> (As a side-benefit, there'd be less griping about not repeating the name in 
> a record declaration. ;-)
> 
> I suspect that this was not done originally in Ada mainly because of 
> concerns about arbitrarily introducing additional identifiers in the middle 
> of other declarations. Not sure that's a real problem; there might be some 
> weird visibility issues that arose.

The thing I see is that if you needed to do something moderately complicated, where a extended-return must be used... There's nothing that lets you do this, to my knowledge, in the language, so we would need a 'TYPE attribute that would return out the given object's type. (We already got the 'Return in Ada 2012 so we could use it in post-conditions.) Then we could have:

SubType Initializing_Info is Boolean; -- To be changed for later/complex items.
Function Testing( Init : Initializing_Info ) Return
        record
           A : Integer;
           B : Float;
         end record
     is begin
         return Result : Testing'Return'Type:=
             (A => 1,
              B => 2.0) do
             if Init then
                 A := 23;
             end if;
         end return;
     end Testing;

There have been a few times I've come across where being able to use the type like that would be advantageous... but no interesting specific example is coming to mind, but with discretes you could make 'Img a bit portable by writing Discrete_var'Type'Image( Discrete_var ) -- A bit wordy, but it would be quite portable in this case and a renames might make that a bit more friendly -- and using streams would be a bit easier if you have things functional but want to use streams and just fiddle with your record components:
Field_Name'Type'Write( [...] );



  reply	other threads:[~2012-08-31 22:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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