Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"It runs like _x, where _x is something unsavory" -- Prof. Romas Aleliunas, CS 435


devel / comp.lang.ada / Aggregate with derived types.

SubjectAuthor
* Aggregate with derived types.Blady
`* Re: Aggregate with derived types.Jeffrey R.Carter
 `* Re: Aggregate with derived types.Blady
  +* Re: Aggregate with derived types.Jeffrey R.Carter
  |`- Re: Aggregate with derived types.Blady
  `- Re: Aggregate with derived types.Randy Brukardt

1
Aggregate with derived types.

<udv3q0$2l5b9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10050&group=comp.lang.ada#10050

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.p11@orange.fr (Blady)
Newsgroups: comp.lang.ada
Subject: Aggregate with derived types.
Date: Thu, 14 Sep 2023 16:02:39 +0200
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <udv3q0$2l5b9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Sep 2023 14:02:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="818daf88bc92539b44f05f222008836b";
logging-data="2790761"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a/Aq/rWBELm2+ATWxTHQm"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
Cancel-Lock: sha1:NjdJMto5dPVz6kvxZSNecEQPaYQ=
Content-Language: fr, en-US
 by: Blady - Thu, 14 Sep 2023 14:02 UTC

Hello,

I want to extend a container type like Vectors, I've written:
type My_Float_List2 is new My_Float_Lists.Vector with null record;

But the initialization gives an error line 6:

1. with Ada.Containers.Vectors;
2. with Ada.Text_IO;
3. procedure test_20230914_derived_agg is
4. package My_Float_Lists is new Ada.Containers.Vectors
(Positive, Float);
5. subtype My_Float_List1 is My_Float_Lists.Vector;
6. type My_Float_List2 is new My_Float_Lists.Vector with null
record;
7. ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
8. ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0] with
null record);
|
>>> error: no unique type for this aggregate
9. begin
10. Ada.Text_IO.Put_Line (ML1.Element (3)'Image);
11. Ada.Text_IO.Put_Line (ML2.Element (3)'Image);
12. end test_20230914_derived_agg;

The RM says:
4.3.2 Extension Aggregates
1 [An extension_aggregate specifies a value for a type that is a record
extension by specifying a value or subtype for an ancestor of the type,
followed by associations for any components not determined by the
ancestor_part.]
Language Design Principles
1.a The model underlying this syntax is that a record extension can
also be viewed as a regular record type with an ancestor
"prefix".
The record_component_association_list corresponds to
exactly what
would be needed if there were no ancestor/prefix type. The
ancestor_part determines the value of the ancestor/prefix.
Syntax
2 extension_aggregate ::=
(ancestor_part with record_component_association_list)
3 ancestor_part ::= expression | subtype_mark

It is not so clear for me what could a unique type?
Any clue?

Thanks Pascal.

Re: Aggregate with derived types.

<udv914$2kqji$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10052&group=comp.lang.ada#10052

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Aggregate with derived types.
Date: Thu, 14 Sep 2023 17:31:47 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <udv914$2kqji$1@dont-email.me>
References: <udv3q0$2l5b9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 14 Sep 2023 15:31:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="07e56f92c66353d191d247ff13a33972";
logging-data="2779762"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WyH4zd2Xt9fnZkYL4pRwHO6vJWyvgFBQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:YXLMLYsn9gvo2OjRwD8D9yd6ciU=
In-Reply-To: <udv3q0$2l5b9$1@dont-email.me>
Content-Language: en-US
 by: Jeffrey R.Carter - Thu, 14 Sep 2023 15:31 UTC

On 2023-09-14 16:02, Blady wrote:
>
>      1. with Ada.Containers.Vectors;
>      2. with Ada.Text_IO;
>      3. procedure test_20230914_derived_agg is
>      4.    package My_Float_Lists is new Ada.Containers.Vectors (Positive, Float);
>      5.    subtype My_Float_List1 is My_Float_Lists.Vector;
>      6.    type My_Float_List2 is new My_Float_Lists.Vector with null record;
>      7.    ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
>      8.    ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0] with null
> record);
>                                     |
>         >>> error: no unique type for this aggregate

IIUC, you have to qualify the value:

(My_Float_List1'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)

or

(My_Float_Lists.Vector'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)

(not tested)

--
Jeff Carter
"[M]any were collected near them, ... to
enjoy the sight of a dead young lady, nay,
two dead young ladies, for it proved twice
as fine as the first report."
Persuasion
155

Re: Aggregate with derived types.

<udvooj$2oveh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10053&group=comp.lang.ada#10053

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.p11@orange.fr (Blady)
Newsgroups: comp.lang.ada
Subject: Re: Aggregate with derived types.
Date: Thu, 14 Sep 2023 22:00:19 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <udvooj$2oveh$1@dont-email.me>
References: <udv3q0$2l5b9$1@dont-email.me> <udv914$2kqji$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 14 Sep 2023 20:00:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8143c6364d43b82ae9baf354387a001e";
logging-data="2915793"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19f9l+mnFiTcROLdAGHXTAA"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
Cancel-Lock: sha1:WGVY0gKbjK3XHllz3s+YsMWcz7M=
Content-Language: fr, en-US
In-Reply-To: <udv914$2kqji$1@dont-email.me>
 by: Blady - Thu, 14 Sep 2023 20:00 UTC

Le 14/09/2023 à 17:31, Jeffrey R.Carter a écrit :
> On 2023-09-14 16:02, Blady wrote:
>>
>>       1. with Ada.Containers.Vectors;
>>       2. with Ada.Text_IO;
>>       3. procedure test_20230914_derived_agg is
>>       4.    package My_Float_Lists is new Ada.Containers.Vectors
>> (Positive, Float);
>>       5.    subtype My_Float_List1 is My_Float_Lists.Vector;
>>       6.    type My_Float_List2 is new My_Float_Lists.Vector with null
>> record;
>>       7.    ML1 : My_Float_List1 := [-3.1, -6.7, 3.3, -3.14, 0.0];
>>       8.    ML2 : My_Float_List2 := ([-3.1, -6.7, 3.3, -3.14, 0.0]
>> with null record);
>>                                      |
>>          >>> error: no unique type for this aggregate
>
> IIUC, you have to qualify the value:
>
> (My_Float_List1'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)
>
> or
>
> (My_Float_Lists.Vector'[-3.1, -6.7, 3.3, -3.14, 0.0] with null record)
>
> (not tested)

Thanks Jeff, both proposals are compiled ok by GNAT.

I wonder why the float list aggregate isn't inferred by the compiler and
need some help with a qualification.

Re: Aggregate with derived types.

<udvufb$2opvr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10054&group=comp.lang.ada#10054

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Aggregate with derived types.
Date: Thu, 14 Sep 2023 23:37:47 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <udvufb$2opvr$1@dont-email.me>
References: <udv3q0$2l5b9$1@dont-email.me> <udv914$2kqji$1@dont-email.me>
<udvooj$2oveh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Sep 2023 21:37:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="84a51ffbd2848b7d154f82a468fd34f6";
logging-data="2910203"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VSEhPkGvEu6XkEmvDmp2Lm6Rb9UUNyso="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:RXZSJYA1WYQYT+DhJQR9vnZaQjA=
In-Reply-To: <udvooj$2oveh$1@dont-email.me>
Content-Language: en-US
 by: Jeffrey R.Carter - Thu, 14 Sep 2023 21:37 UTC

On 2023-09-14 22:00, Blady wrote:
>
> I wonder why the float list aggregate isn't inferred by the compiler and need
> some help with a qualification.

I'm not sure. But can't you simply write

ML2 : My_Float_List2 := [-3.1, -6.7, 3.3, -3.14, 0.0];

? I presume that My_Float_List2 inherits its aggregate definition from
My_Float_List1.

--
Jeff Carter
"[M]any were collected near them, ... to
enjoy the sight of a dead young lady, nay,
two dead young ladies, for it proved twice
as fine as the first report."
Persuasion
155

Re: Aggregate with derived types.

<ue111u$34tmh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10055&group=comp.lang.ada#10055

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.p11@orange.fr (Blady)
Newsgroups: comp.lang.ada
Subject: Re: Aggregate with derived types.
Date: Fri, 15 Sep 2023 09:27:57 +0200
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <ue111u$34tmh$1@dont-email.me>
References: <udv3q0$2l5b9$1@dont-email.me> <udv914$2kqji$1@dont-email.me>
<udvooj$2oveh$1@dont-email.me> <udvufb$2opvr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 15 Sep 2023 07:27:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cc85bafdc724e3723e7182e61de4ce8a";
logging-data="3307217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vaZn4pmXfdWVb5e58KqQy"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
Cancel-Lock: sha1:ry0oKkdyI37Zpa8pIm1/xKCnPGA=
Content-Language: fr, en-US
In-Reply-To: <udvufb$2opvr$1@dont-email.me>
 by: Blady - Fri, 15 Sep 2023 07:27 UTC

Le 14/09/2023 à 23:37, Jeffrey R.Carter a écrit :
> On 2023-09-14 22:00, Blady wrote:
>>
>> I wonder why the float list aggregate isn't inferred by the compiler
>> and need some help with a qualification.
>
> I'm not sure. But can't you simply write
>
> ML2 : My_Float_List2 := [-3.1, -6.7, 3.3, -3.14, 0.0];
>
> ? I presume that My_Float_List2 inherits its aggregate definition from
> My_Float_List1.

Unfortunately not directly:
10. ML2c : My_Float_List2 := [-3.1, -6.7, 3.3, -3.14, 0.0];
|
>>> error: type of aggregate has private ancestor "Vector"
>>> error: must use extension aggregate

Shouldn't inherit them?

Indeed you have it if you defined a private extension with explicit aspects:
package PA is
type My_Float_List3 is new My_Float_Lists.Vector with private with
Constant_Indexing => Constant_Reference,
Variable_Indexing => Reference,
Default_Iterator => Iterate,
Iterator_Element => Float,
Aggregate =>
(Empty => Empty, Add_Unnamed => Append, New_Indexed =>
New_Vector, Assign_Indexed => Replace_Element);
function Constant_Reference
(Container : aliased My_Float_List3; Index : Positive) return
My_Float_Lists.Constant_Reference_Type is
(My_Float_Lists.Constant_Reference (My_Float_Lists.Vector
(Container), Index));
function Reference (Container : aliased in out My_Float_List3;
Index : Positive) return My_Float_Lists.Reference_Type is
(My_Float_Lists.Reference (My_Float_Lists.Vector (Container),
Index));
private
type My_Float_List3 is new My_Float_Lists.Vector with null record;
end PA;

ML3 : PA.My_Float_List3 := [-3.1, -6.7, 3.3, -3.14, 0.0];

Re: Aggregate with derived types.

<ue3ij6$3m5td$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10063&group=comp.lang.ada#10063

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: Aggregate with derived types.
Date: Sat, 16 Sep 2023 01:39:57 -0500
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <ue3ij6$3m5td$1@dont-email.me>
References: <udv3q0$2l5b9$1@dont-email.me> <udv914$2kqji$1@dont-email.me> <udvooj$2oveh$1@dont-email.me>
Injection-Date: Sat, 16 Sep 2023 06:39:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1cae056933789323815d911d86a9da8e";
logging-data="3872685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z7AA/pumV3M8fKCL9vconXeQXUreicis="
Cancel-Lock: sha1:RDZi9Z4q3MmjxrwHw11xCh9vJCU=
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-MSMail-Priority: Normal
X-Priority: 3
 by: Randy Brukardt - Sat, 16 Sep 2023 06:39 UTC

"Blady" <p.p11@orange.fr> wrote in message
news:udvooj$2oveh$1@dont-email.me...
....
> I wonder why the float list aggregate isn't inferred by the compiler and
> need some help with a qualification.

The language rule is that the ancestor_part of an extension aggregate is
expected to be of "any tagged type" (see 4.3.2(4/2)). An aggregate needs to
have a single specific type, and "any tagged type" is not that.

The reason that the ancestor is "any tagged type" is that the type of the
ancestor determines the extension components needed along with other
legality rules. One could imagine a language where all of these things are
decided simulateously, but people worried that the complexity would make it
difficult/impossible to implement. So aggregates are essentially black boxes
whose type has to be determinable from the outside, and similar rules exist
for parts inside the aggregate.

Randy.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor