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!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Discriminant of a limited type object Date: Wed, 28 Feb 2018 09:42:13 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: MyFhHs417jM9AgzRpXn7yg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:50700 Date: 2018-02-28T09:42:13+01:00 List-Id: On 28/02/2018 07:36, J-P. Rosen wrote: > Le 27/02/2018 à 23:53, Dmitry A. Kazakov a écrit : >>    A : T (1..N); >> begin >>    for Index in A'Range loop >>       do-init of A (Index) >>    end loop; >> >>         | >>         V >> >>    Index : Positive := 1; >>    function F return Element is >>    begin >>       Index := Index + 1; >>       return do-init of A (Index - 1); >>    end F; >>    A : T (1..N) := (others => F) > But this does not guarantee the order of components. I'd rather write > (changing do_init to a function): > function Init_All (Size : Integer) return T is > begin > if Size = 1 then > return (1 => do_init) > else > return do_init & Init_All (size - 1); > end if; > end; > > A : T := Init_All (N); You are right, I forgot about the arbitrary order of initialization! It was mad already. Recursion adds a new level of madness into it. (Provided GNAT would generate working the code at all. It has issues with limited return in much simpler cases.) But it is still arbitrary order in "&" arguments. Though do_init could take as an argument N - Size + 1 in order to determine the element's index, any other external state is not guaranteed. E.g. initialization of A (I + 1) cannot depend on initialization of A (I). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de