Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
anonymous aggregates?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Stephen Leake  
View profile  
 More options Aug 31 2012, 6:22 am
Newsgroups: comp.lang.ada
From: Stephen Leake <stephen_le...@stephe-leake.org>
Date: Fri, 31 Aug 2012 06:22:35 -0400
Local: Fri, Aug 31 2012 6:22 am
Subject: anonymous aggregates?
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Drummond  
View profile  
 More options Aug 31 2012, 7:06 am
Newsgroups: comp.lang.ada
From: Brian Drummond <br...@shapes.demon.co.uk>
Date: Fri, 31 Aug 2012 11:06:24 +0000 (UTC)
Local: Fri, Aug 31 2012 7:06 am
Subject: Re: anonymous aggregates?

On Fri, 31 Aug 2012 06:22:35 -0400, Stephen Leake wrote:
> Occasionally I have the following pattern:

> declare
>     A : Integer;
>     B : Float;

>     procedure Foo (A : out Integer; B : out Float);

...

> 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;
...
> But that seems like overkill, especially since the code in "..." must be
> edited; all references to A must be replaced by A_B.A.

All references, or just one?

(in the declarations section, just after the initialisation of A_B)
A : constant Integer renames A_B.A;

- Brian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmitry A. Kazakov  
View profile  
 More options Aug 31 2012, 8:02 am
Newsgroups: comp.lang.ada
From: "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
Date: Fri, 31 Aug 2012 14:02:03 +0200
Local: Fri, Aug 31 2012 8:02 am
Subject: Re: anonymous aggregates?

There are two separate issues here:

1. anonymous record types, one of the things I liked to have very much as
well as an ability to use anonymous arrays and aggregates as components.

The syntax is obvious:

function Foo return
   record
      A : Integer;
      B : Float;
   end record;

2. Usage of aggregates (of any kind) on the left side of assignment and in
out parameters. One could consider Ada 2012 aliased parameters somehow
extended on record components and array elements.

Another possible mechanism could be argument type conversion as in Ada 83
when a tuple (A, B) explicitly converted to a record as out parameter. This
roughly corresponds to your idea.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Beneschan  
View profile  
 More options Aug 31 2012, 11:15 am
Newsgroups: comp.lang.ada
From: Adam Beneschan <a...@irvine.com>
Date: Fri, 31 Aug 2012 08:15:39 -0700 (PDT)
Local: Fri, Aug 31 2012 11:15 am
Subject: Re: anonymous aggregates?

On Friday, August 31, 2012 5:02:03 AM UTC-7, Dmitry A. Kazakov wrote:

> There are two separate issues here:

> 1. anonymous record types, one of the things I liked to have very much as
> well as an ability to use anonymous arrays and aggregates as components.

> The syntax is obvious:

> function Foo return
>    record
>       A : Integer;
>       B : Float;
>    end record;

I seem to recall someone saying, probably on this newsgroup, that the early designers of Ada were keeping open the possibility of anonymous record types.  That's one reason why the syntax ends with "end record" instead of "end <typename>" (just to tie this to a different thread!).  It could be that the original version of the language had anonymous record types somewhere in the syntax, and it got eliminated before Ada 83 was standardized.  But I don't really know.

                               -- Adam


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Randy Brukardt  
View profile  
 More options Aug 31 2012, 6:37 pm
Newsgroups: comp.lang.ada
From: "Randy Brukardt" <ra...@rrsoftware.com>
Date: Fri, 31 Aug 2012 17:37:48 -0500
Local: Fri, Aug 31 2012 6:37 pm
Subject: Re: anonymous aggregates?
"Stephen Leake" <stephen_le...@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.

                                       Randy.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shark8  
View profile  
 More options Aug 31 2012, 6:57 pm
Newsgroups: comp.lang.ada
From: Shark8 <onewingedsh...@gmail.com>
Date: Fri, 31 Aug 2012 15:57:52 -0700 (PDT)
Local: Fri, Aug 31 2012 6:57 pm
Subject: Re: anonymous aggregates?

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( [...] );


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Georg Bauhaus  
View profile  
 More options Sep 1 2012, 5:57 am
Newsgroups: comp.lang.ada
From: Georg Bauhaus <rm.dash-bauh...@futureapps.de>
Date: Sat, 01 Sep 2012 11:57:48 +0200
Local: Sat, Sep 1 2012 5:57 am
Subject: Re: anonymous aggregates?
On 01.09.12 00:37, Randy Brukardt wrote:

Wouldn't we be passing objects of anonymous_type_1 that right now
cannot be assigned to anything of anonymous_type_2?
At least not without resorting to types being the same if they
happen use the same structure (and component names?), thus giving up
Ada's notion of type equivalence.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Leake  
View profile  
 More options Sep 2 2012, 7:25 am
Newsgroups: comp.lang.ada
From: Stephen Leake <stephen_le...@stephe-leake.org>
Date: Sun, 02 Sep 2012 07:25:25 -0400
Local: Sun, Sep 2 2012 7:25 am
Subject: Re: anonymous aggregates?

Good point; anonymous arrays are different types, and cannot be assigned
to each other. So anonymous records should be the same, which defeats
the purpose.

--
-- Stephe


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmitry A. Kazakov  
View profile  
 More options Sep 2 2012, 8:34 am
Newsgroups: comp.lang.ada
From: "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
Date: Sun, 2 Sep 2012 14:34:14 +0200
Local: Sun, Sep 2 2012 8:34 am
Subject: Re: anonymous aggregates?

On Sun, 02 Sep 2012 07:25:25 -0400, Stephen Leake wrote:
> Good point; anonymous arrays are different types, and cannot be assigned
> to each other. So anonymous records should be the same, which defeats
> the purpose.

But you didn't want to assign records. Initialization /= assignment.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »