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:a05:620a:1269:: with SMTP id b9mr9219616qkl.401.1574528241093; Sat, 23 Nov 2019 08:57:21 -0800 (PST) X-Received: by 2002:aca:1205:: with SMTP id 5mr16463467ois.51.1574528240783; Sat, 23 Nov 2019 08:57:20 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g89no2887283qtd.0!news-out.google.com!p4ni1612qtu.1!nntp.google.com!g89no2887274qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 23 Nov 2019 08:57:20 -0800 (PST) In-Reply-To: <358a3934-7cb2-4cff-8703-71410815f27e@googlegroups.com> 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: <371cb59c-1814-4953-9652-43c9986808a1@googlegroups.com> Subject: Re: Initializing an array of tasks with discrimants From: Jere Injection-Date: Sat, 23 Nov 2019 16:57:21 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57604 Date: 2019-11-23T08:57:20-08:00 List-Id: On Friday, November 22, 2019 at 5:07:49 PM UTC-5, 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: > > task type T(D: Integer := 3); > > task body T is > begin > null; > end T; > > type A is array (Integer range <>) of T; > > V : A(1..10) := ????????? > > If they all had the same discriminant value, I > can just create a subtype and do an array of > the subtype, but in this case, the discriminants > would not all be the same. > > My work around was a wrapper type: > > type Wrapper(D : Integer := 0) is record > Impl : T(D); > end record. > > type A is array (Integer range <>) of Wrapper; > > V : A(1..10) := (1 => (D => 1, others => <>), and so on > > But I was hoping there was a better way to do it simply. > The Wrapper record isn't there to represent the > intended design and doesn't really improve readability. > It's essentially a workaround for something I cannot > figure out. > > I tried many variations of qualified expressions and > aggregates on the original task type elements, but all > of them gave me errors about it expected the task type > but found a composite type instead. > > Is there a particular aggregate that I can use to avoid > the superfluous wrapper record? One other option I didn't think of which is definitely better than the wrapper record is a constructing function: function Make_Task(Option : Integer) return T is begin return Result : Task(Option); end Make_Task; That lets me do things like: A : T_Array(1..10) := (1 => Make_Task(2), 2 => Make_Task(5), others => Make_Task(20)); I still think Ada should support aggregates for Tasks with discriminants in some form. I'm hoping the 2020 change mentioned earlier will help with that (though I never identified how when reading over it...I'll spend some more time looking for it).