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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Initializing an array of tasks with discrimants Date: Fri, 22 Nov 2019 23:39:53 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <358a3934-7cb2-4cff-8703-71410815f27e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 22 Nov 2019 22:39:53 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="0ef0e5926dfb0433c6da5c4900890ade"; logging-data="4653"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fWi/z8pFNPdMXYlnUMnIUS3fBPR84dKg=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 Cancel-Lock: sha1:+W3D/E2p6oNoIZmCaOFlxT6ta8M= In-Reply-To: <358a3934-7cb2-4cff-8703-71410815f27e@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57595 Date: 2019-11-22T23:39:53+01:00 List-Id: 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. -- Jeff Carter "I would never want to belong to any club that would have someone like me for a member." Annie Hall 41