comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Initializing an array of tasks with discrimants
Date: Sat, 23 Nov 2019 08:23:34 -0800 (PST)
Date: 2019-11-23T08:23:34-08:00	[thread overview]
Message-ID: <7936eab3-47c2-46d1-9c28-95730fb222b7@googlegroups.com> (raw)
In-Reply-To: <qr9o3p$4hd$1@dont-email.me>

On Friday, November 22, 2019 at 5:39:57 PM UTC-5, Jeffrey R. Carter wrote:
> On 11/22/19 11:07 PM, Jere wrote:
> > I recently ran into a situation where I had an array
> > of tasks that had discriminants (with a default), but
> > I couldn't find a simple way to initialize them.  I
> > did come up with a workaround, but wanted to see if
> > the language defined a way to do this:
> 
> The standard way to do this is for the default to be a function call:
> 
> Next_Value : Positive := 1;
> 
> function Next return Positive is
>     Result : constant Positive := Next_Value;
> begin -- Next
>     Next_Value := Next_Value + 1;
> 
>     return Result;
> end Next;
> 
> task type T (D : Positive := Next);
> 
> type T_List is array (Positive range <>) of T;
> 
> A : T_List (1 .. Num_Tasks);
> 
> The language guarantees that the calls to Next will occur sequentially. The 
> order of the calls is not defined, so there is no guarantee that the index and 
> discriminant of a T in A will be the same.
> 

Thanks!  That said, my issue isn't so much generating the numbers
(They would not have any particular pattern anyways), but trying
to figure out if there is an aggregate or qualified expression for
initializing tasks with discriminants that I could use.  I was hoping
that simply T'(D => 2) would have worked, but the compiler complains
about being a composite.  On one level I understand why, but on another
given how strongly typed Ada is, I was hoping the language provided
some type of initialization aggregate.

This is still a good solution for when the discriminants will have  a
known pattern by design though.  I will file it away for that
situation, so thank you.

  reply	other threads:[~2019-11-23 16:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 22:07 Initializing an array of tasks with discrimants Jere
2019-11-22 22:39 ` Jeffrey R. Carter
2019-11-23 16:23   ` Jere [this message]
2019-11-22 23:57 ` Robert A Duff
2019-11-23  0:27   ` Anh Vo
2019-11-23  9:12   ` Randy Brukardt
2019-11-23 16:50     ` Jere
2019-11-23 16:25   ` Jere
2019-11-23  8:29 ` Dmitry A. Kazakov
2019-11-23 16:28   ` Jere
2019-11-23 17:03     ` Dmitry A. Kazakov
2019-11-23 16:57 ` Jere
2019-11-25 22:36   ` Randy Brukardt
replies disabled

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