From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Why does Ada.Iterator_Interfaces specify Next as a function rather than a procedure?
Date: Thu, 7 Sep 2017 18:14:20 -0500
Date: 2017-09-07T18:14:20-05:00 [thread overview]
Message-ID: <oosjsd$bjr$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: ba860d9f-7e5f-431b-826b-76a6347db38e@googlegroups.com
I think you're confusing the cursor and the iterator object. (Next has two
parameters, after all.) I'm talking about the definition of the iterator
object; that's where you keep any state necessary. The cursor just provides
a reference to the current item, whatever that might be.
The instantiation takes the cursor type; it then is used to define the
actual iterator type.
In almost all cases, the iterator object has to be separate from the
underlying data structure; generally you define a function to create the
initial iterator object. (There are aspects to automate this process, look
at how the containers are structured if you want to try to use them.) One
reason for this is the possibility that multiple tasks might iterate over
the same read-only object.
Randy.
"Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message
news:ba860d9f-7e5f-431b-826b-76a6347db38e@googlegroups.com...
> On Wednesday, September 6, 2017 at 8:04:15 PM UTC-5, Stephen Leake wrote:
>> > type State is record
>> > -- The components of the state.
>> > end record;
>> >
>> > type My_Iterator is new Ada.Finalization.Controlled and
>> > Reversible_Iterator with record
>> > My_State : access State; -- Writable state.
>> > The_State : aliased State;
>> > end record;
>
> I don't see how to do this; 'Reversible_Iterator' is defined in an
> instantiation of Ada.Iterator_Interfaces, which takes the type My_Iterator
> as a generic parameter.
>
> Just leaving that off still fails, if I try to make the contents of the
> cursor private while exposing the Iterate function.
>
> Are you relying on some new Ada 202x syntax here?
>> >
>> > procedure Initialize (Obj : in out My_Iterator) is
>> > begin
>> > Obj.My_State := The_State'Access; -- (*)
>> > end Initialize;
>>
>> > This is a legitimate technique -- it is NOT erroneous in Ada
>> > 2012 -- so if your compiler has problems with it, file a bug report and
>> > if
>> > they don't believe that, send me a proposed ACATS test!
>>
>> You are implying that my worry about the compiler assuming the input and
>> output of Next must point to different items is not valid.
>>
>> I'll give it a try.
>>
>> -- Stephe
>
next prev parent reply other threads:[~2017-09-07 23:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-06 7:49 Why does Ada.Iterator_Interfaces specify Next as a function rather than a procedure? Stephen Leake
2017-09-06 21:50 ` Randy Brukardt
2017-09-07 1:04 ` Stephen Leake
2017-09-07 1:29 ` Stephen Leake
2017-09-07 23:14 ` Randy Brukardt [this message]
2017-09-07 2:53 ` Charles H. Sampson
2017-09-07 6:16 ` briot.emmanuel
2017-09-07 23:17 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox