comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Discriminant of a limited type object
Date: Wed, 28 Feb 2018 09:42:13 +0100
Date: 2018-02-28T09:42:13+01:00	[thread overview]
Message-ID: <p75q15$1796$1@gioia.aioe.org> (raw)
In-Reply-To: p75ilv$rqm$1@gioia.aioe.org

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


  reply	other threads:[~2018-02-28  8:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 17:54 Discriminant of a limited type object Dmitry A. Kazakov
2018-02-27 22:20 ` Randy Brukardt
2018-02-27 22:53   ` Dmitry A. Kazakov
2018-02-28  6:36     ` J-P. Rosen
2018-02-28  8:42       ` Dmitry A. Kazakov [this message]
2018-02-28  9:07         ` J-P. Rosen
2018-02-28 17:16       ` Jeffrey R. Carter
2018-02-28 23:10     ` Randy Brukardt
2018-03-01  8:43       ` Dmitry A. Kazakov
2018-03-01 22:00         ` Randy Brukardt
2018-03-02 10:30           ` Dmitry A. Kazakov
replies disabled

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