From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a37:aa11:: with SMTP id t17mr14380027qke.60.1574526215353; Sat, 23 Nov 2019 08:23:35 -0800 (PST) X-Received: by 2002:aca:530c:: with SMTP id h12mr17441120oib.110.1574526215074; Sat, 23 Nov 2019 08:23:35 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no2802226qtd.0!news-out.google.com!p4ni1612qtu.1!nntp.google.com!g89no2802221qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 23 Nov 2019 08:23:34 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: <358a3934-7cb2-4cff-8703-71410815f27e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <7936eab3-47c2-46d1-9c28-95730fb222b7@googlegroups.com> Subject: Re: Initializing an array of tasks with discrimants From: Jere Injection-Date: Sat, 23 Nov 2019 16:23:35 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57600 Date: 2019-11-23T08:23:34-08:00 List-Id: 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.