Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Save yourself! Reboot in 5 seconds!


devel / comp.lang.ada / Re: Arrays with discriminated task components

SubjectAuthor
* Arrays with discriminated task componentsAdaMagica
+* Re: Arrays with discriminated task componentsNiklas Holsti
|`* Re: Arrays with discriminated task componentsJeffrey R.Carter
| `- Re: Arrays with discriminated task componentsNiklas Holsti
`* Re: Arrays with discriminated task componentsNiklas Holsti
 `- Re: Arrays with discriminated task componentsAdaMagica

1
Arrays with discriminated task components

<9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:4403:0:b0:3a7:f2b0:c4c0 with SMTP id j3-20020ac84403000000b003a7f2b0c4c0mr546084qtn.490.1671882268223;
Sat, 24 Dec 2022 03:44:28 -0800 (PST)
X-Received: by 2002:a05:620a:1fc:b0:6ee:bbea:1ebb with SMTP id
x28-20020a05620a01fc00b006eebbea1ebbmr628246qkn.638.1671882268084; Sat, 24
Dec 2022 03:44:28 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 24 Dec 2022 03:44:27 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=94.31.100.23; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 94.31.100.23
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
Subject: Arrays with discriminated task components
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Sat, 24 Dec 2022 11:44:28 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1594
 by: AdaMagica - Sat, 24 Dec 2022 11:44 UTC

I've got a task type with a discriminant:

type Index is range 1 .. N;

task type T (D: Index);

Now I want an array of these tasks, where each task knows its identity (the index) via the discriminant, an iterated_component_association:

Arr: array (Index) of T := (for I in Index => ???);

How can I do this?

This works with access, but I find this extremely ugly:

Arr: array (Index) of access T := (for I in Index => new T (I));

Alternatively, I could use the traditional method with a Start entry with the index as parameter:

task type T is
entry Start (D: Index);
end T;

Re: Arrays with discriminated task components

<k0otavF33okU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Arrays with discriminated task components
Date: Sat, 24 Dec 2022 20:05:19 +0200
Organization: Tidorum Ltd
Lines: 46
Message-ID: <k0otavF33okU1@mid.individual.net>
References: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 34g712XPyjb3D/ff1IBmmwn9lW31oXkNNaw6ZZfXK2FxJ1QbTr
Cancel-Lock: sha1:EQnJPAzetRlmv8rTj9t8ZJKnbng=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.5.1
Content-Language: en-US
In-Reply-To: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
 by: Niklas Holsti - Sat, 24 Dec 2022 18:05 UTC

On 2022-12-24 13:44, AdaMagica wrote:
> I've got a task type with a discriminant:
>
> type Index is range 1 .. N;
>
> task type T (D: Index);
>
> Now I want an array of these tasks, where each task knows its
> identity (the index) via the discriminant, an
> iterated_component_association: >
> Arr: array (Index) of T := (for I in Index => ???);
>
> How can I do this?

One way is to give the discrimant a default value that is a function
call that returns a new identifier on each call:

Next_Index : Index := Index'First;
-- The value returned by the next call of New_Index.

function New_Index return Index
-- Returns a unique Index value (up to N).
is
Result : constant Index := Next_Index;
begin
if Next_Index < Index'Last then
Next_Index := Next_Index + 1;
-- else report error?
end if;
return Result;
end New_Index;

task type T (D: Index := New_Index);

Then you can declare the array without any initial value:

Arr: array (Index) of T;

and the initialization of each task in the array makes its own call to
New_Index and gets its own identifier value.

A bit sneaky, but has the advantage that it extends automatically to
two arrays of tasks, or one array and some separate single declarations
of tasks, etc.

Re: Arrays with discriminated task components

<to7v6v$2cjc4$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Arrays with discriminated task components
Date: Sat, 24 Dec 2022 23:41:34 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <to7v6v$2cjc4$1@dont-email.me>
References: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
<k0otavF33okU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 24 Dec 2022 22:41:37 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="030fb7bc385e68993db4e7309219bc3c";
logging-data="2510212"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Uw/G997Sn7wYEV1jp+m2+/tPbVm5tTz4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:3ipaO6aFeAzWs9lmUNYBfBmIRp0=
Content-Language: en-US
In-Reply-To: <k0otavF33okU1@mid.individual.net>
 by: Jeffrey R.Carter - Sat, 24 Dec 2022 22:41 UTC

On 2022-12-24 19:05, Niklas Holsti wrote:
> On 2022-12-24 13:44, AdaMagica wrote:
>>
>> Now I want an array of these tasks, where each task knows its identity (the
>> index) via the discriminant, an
>> iterated_component_association: >
>> Arr: array (Index) of T := (for I in Index => ???);
>
> One way is to give the discrimant a default value that is a function call that
> returns a new identifier on each call:

No, this does not guarantee that the task's discriminant is its index in the
array, which is a requirement of the question.

--
Jeff Carter
"My mind is aglow with whirling, transient nodes of
thought, careening through a cosmic vapor of invention."
Blazing Saddles
85

Re: Arrays with discriminated task components

<k0r8orFdlkfU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Arrays with discriminated task components
Date: Sun, 25 Dec 2022 17:32:43 +0200
Organization: Tidorum Ltd
Lines: 20
Message-ID: <k0r8orFdlkfU1@mid.individual.net>
References: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
<k0otavF33okU1@mid.individual.net> <to7v6v$2cjc4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net /uLGqva8V/PdJzORDgFYZAx1lUYexTxLR4HACgHxQ9HqqqpV5y
Cancel-Lock: sha1:TYiTmL9ph4F74XIbRTZ09YoAgpM=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.5.1
Content-Language: en-US
In-Reply-To: <to7v6v$2cjc4$1@dont-email.me>
 by: Niklas Holsti - Sun, 25 Dec 2022 15:32 UTC

On 2022-12-25 0:41, Jeffrey R.Carter wrote:
> On 2022-12-24 19:05, Niklas Holsti wrote:
>> On 2022-12-24 13:44, AdaMagica wrote:
>>>
>>> Now I want an array of these tasks, where each task knows its
>>> identity (the index) via the discriminant, an
>>> iterated_component_association: >
>>> Arr: array (Index) of T := (for I in Index => ???);
>>
>> One way is to give the discrimant a default value that is a function
>> call that returns a new identifier on each call:
>
> No, this does not guarantee that the task's discriminant is its index in
> the array, which is a requirement of the question.

Right, I did not take that requirement into account, apologies for my
inattention. Indeed the tasks in the array are initialized in an
arbitrary order, not necessarily in increasing index order.

Re: Arrays with discriminated task components

<k0rbboFdlkeU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: Arrays with discriminated task components
Date: Sun, 25 Dec 2022 18:16:56 +0200
Organization: Tidorum Ltd
Lines: 52
Message-ID: <k0rbboFdlkeU1@mid.individual.net>
References: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net SebDP3aXLB760DJUQmROgAjfvQE5A89eyEN5D8WezMUzgkQ5/H
Cancel-Lock: sha1:98EQCZ1P2G8wOwSUCgK40GkLX7g=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.5.1
Content-Language: en-US
In-Reply-To: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com>
 by: Niklas Holsti - Sun, 25 Dec 2022 16:16 UTC

On 2022-12-24 13:44, AdaMagica wrote:
> I've got a task type with a discriminant:
>
> type Index is range 1 .. N;
>
> task type T (D: Index);
>
> Now I want an array of these tasks, where each task knows its
> identity (the index) via the discriminant, an iterated_component_association:
>
> Arr: array (Index) of T := (for I in Index => ???);
>
> How can I do this?
>
> This works with access, but I find this extremely ugly:
>
> Arr: array (Index) of access T := (for I in Index => new T (I));
>
> Alternatively, I could use the traditional method with a Start entry with the index as parameter:
>
> task type T is
> entry Start (D: Index);
> end T;

This seems to work with gnat, but I'm not entirely sure if it is legal
(could there be a conflict between the default value of the task
discriminant, which is the same for all tasks in the array, and the
actual discriminants which are different for each task in the array?):

N : constant := 10;

type Index is range 1 .. N;

task type T (D: Index := Index'First);
-- A default value for D is needed to make the type constrained, as
-- required by the Arr declaration below.

function New_T (I : in Index)
return T
is
begin
return TI : T (D => I)
do
null;
end return;
end New_T;

Arr: array (Index) of T := (for I in Index => New_T(I));

Whether this is any less ugly than the heap allocation method is doubtful.

Re: Arrays with discriminated task components

<8606428f-5400-4add-a665-ccfe5ea29123n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:6348:0:b0:6fe:b359:4896 with SMTP id x69-20020a376348000000b006feb3594896mr661521qkb.579.1672072763663;
Mon, 26 Dec 2022 08:39:23 -0800 (PST)
X-Received: by 2002:a05:620a:1222:b0:6ec:5332:6ebd with SMTP id
v2-20020a05620a122200b006ec53326ebdmr1086039qkj.0.1672072763528; Mon, 26 Dec
2022 08:39:23 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 26 Dec 2022 08:39:23 -0800 (PST)
In-Reply-To: <k0rbboFdlkeU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=94.31.100.23; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 94.31.100.23
References: <9b729cf0-02c7-48e1-8cea-c0d177c4bf3bn@googlegroups.com> <k0rbboFdlkeU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8606428f-5400-4add-a665-ccfe5ea29123n@googlegroups.com>
Subject: Re: Arrays with discriminated task components
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Mon, 26 Dec 2022 16:39:23 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 1
 by: AdaMagica - Mon, 26 Dec 2022 16:39 UTC

Thanx, Niklas and Jeffrey. I just didn't think of the generator function.
Christoph


devel / comp.lang.ada / Re: Arrays with discriminated task components

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor