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!mx02.eternal-september.org!feeder.eternal-september.org!gegeweb.org!news.ecp.fr!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: A few questions Date: Fri, 13 Nov 2015 11:52:29 -0600 Organization: JSA Research & Innovation Message-ID: References: <1dolqizyi8gxi.t3173bhifuu1.dlg@40tude.net> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1447437150 17893 24.196.82.226 (13 Nov 2015 17:52:30 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 13 Nov 2015 17:52:30 +0000 (UTC) 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.6157 Xref: news.eternal-september.org comp.lang.ada:28360 Date: 2015-11-13T11:52:29-06:00 List-Id: "Dmitry A. Kazakov" wrote in message news:1dolqizyi8gxi.t3173bhifuu1.dlg@40tude.net... > On Thu, 12 Nov 2015 15:15:45 -0600, Randy Brukardt wrote: ... >> Surely it is not the same. But why do we need the first? > > For doing this: > > for Line in Read (Text_File) loop > ... > end loop; Note that you used "in" rather than "of" here. And if you did that, there is no problem implementing this in the existing Ada, even as you suggest. ... > Operation Read provides an iterateable container-view of Text_File. There > cannot be any index, because the "buffer" will contain just single line. A "cursor" is not necessarily an array index, as I pointed out earlier in this thread. For anything "on demand", the cursor probably ought to be the data itself. (You'd probably have to use an unbounded string for that, but that's a different problem unrelated to iteration.) ... >> An array is surely >> a container, and we got along just fine for 30 years without being able >> to >> iterate elements of arrays. > > Not every container is an array. There are lots of containers which > semantically have no index. Then provide an iterator implementation where the cursor is an access to the element. ... >> There is always *something* that works as an index. If there isn't, you >> can't iterate (because you can't figure out a reproducible order for >> which >> item is next). > > First, index is more than iteration. Index assumes random access and an > ability to access any number of times. Iteration requires only sequential > access and only visit once. If you equate both, you either burden the > implementation with unnecessary functionality or the clients in order to > catch unsupported actions. Not good. You are giving more properties than necessary to an iteration cursor (which is what we are talking about). There is absolutely no problem with it providing sequential one-time access. You have to program it that way, of course, but it's not hard to do (see the implementation in the ACATS, for one example). I might have confused you by calling it an "index", because it's clear that you're assigning properties to it that I am not. There's no reason that you have to use a for loop parameter as an index! (I often write traditional loops where the loop parameter is not an index.) > Secondly, it is an implementation driven view. The problem space may have > no index even when the implementation could have one. Exposing > implementation details is bad. That's the Bag arrgument again. I think that particular data structure is a fraud, because it cannot be created in practice -- plus you have to have some sort of access to the elements, so you end up with a cursor of some sort anyway. There's a reason there is no Bag in the Ada.Containers library! Randy.