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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fa18fb47ddd229a7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-20 11:08:03 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 20 Dec 2003 13:08:01 -0600 Date: Sat, 20 Dec 2003 14:08:00 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Proposed change to BC iterator parameters References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-rTG61CTwmebh+ROTmlmXyTher+H8q5DlSLii9htptlOpR366gXH7AUdPYqbMEUOhFmPxH4Ocy+mirb2!urZnmzXqPYMc43Ff0Sc5IzshVrVHRM8lPlHIlpZALhjumCeVCHRQ1UNt0/bwEA== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:3637 Date: 2003-12-20T14:08:00-05:00 List-Id: Robert A Duff wrote: > Cursors are fine when you need that power, but if all you want to do is > loop through the elements of a data structure, it's too low level. The > client shouldn't have to worry about getting the next thing, and testing > for done. The client should just say "for each item X, perform > so-and-so operations on X". That's pretty much what the generic style > does, but the syntax is horrible, and it doesn't work in all cases. For > example, as Jeff Carter pointed out, if the iterator wants to be a > protected operation. I'm a big fan of asking for what you want, then seeing if what you get satisfies your need. Right now I can say: for I in A'Range loop Do_Something(A(I)); end loop; or while List.Next /= null loop; List := List.Next; Do_Something(List.Data); end loop; What Bob seems to be asking for is a way to do that for general data structures: package My_Structures is new Some_Structure(Element); type My_Structure renames My_Structures.Structure; for E in My_Structures.Ordered_List_of_Elements loop Do_Something(E); end loop; Currently I often provide tools in my data structures packages to provide everything viewed as an array. This allows me to do what Bob wants, but it would be really nice to extend the language so that iterators are first class objects known to the language so that the above pseudo code (for E in ...) would be supported if the Some_Structure package provided an iterator. You should also be able to say if E in My_Structures.Some_Iterator then ... (This would require another signature in the template for iterators to make it efficient.) Do I think this will make it into Ada 0Y? No. Ada 1Z? Possibly. But the trick of having data structure packages return an array view of a collection, or actually an array of access values, is very, very useful. (Notice that the difference between such an iterator and normal iterators is that it provides a snapshot. Changes to the actual data structure while iterating through the array won't be visible in the loop. Often this is what you want. Sometimes it isn't, then it gets painful...) -- Robert I. Eachus "The war on terror is a different kind of war, waged capture by capture, cell by cell, and victory by victory. Our security is assured by our perseverance and by our sure belief in the success of liberty." -- George W. Bush