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!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada 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 Organization: JSA Research & Innovation Message-ID: References: <693d41af-1da7-4c47-825a-198a082aaf9a@googlegroups.com> <9677f15f-c612-4ac4-9c2d-64fbf530873e@googlegroups.com> Injection-Date: Thu, 7 Sep 2017 23:14:21 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="11899"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: news.eternal-september.org comp.lang.ada:47976 Date: 2017-09-07T18:14:20-05:00 List-Id: 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" 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 >