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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,effb80d4bb7716dd X-Google-Attributes: gid103376,public From: Brian Rogoff Subject: Re: Wanted: Ada STL. Reward: Ada's Future Date: 1999/02/04 Message-ID: #1/1 X-Deja-AN: 440680632 References: <790f4q$3l@bgtnsc01.worldnet.att.net> <36B856E4.D921C1D@bton.ac.uk> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: nntp1.ba.best.com 918153272 16662 bpr@206.184.139.136 MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-02-04T00:00:00+00:00 List-Id: On 4 Feb 1999, Stephen Leake wrote: > Brian Rogoff writes: > > On Wed, 3 Feb 1999, Matthew Heaney wrote: > > > ... snip ... > > > > > > for Index in Map'Range loop > > > > > > > > > > > > end loop; > > > > > > If this looks simpler than my earlier formulation, that's because it's > > > simpler. Loop iteration in Ada is less error prone than in C. > > > > > > This is yet another reason why I think that looking at the STL as a > > > model for a standard Ada library is dangerous and misleading. > > > > Indeed. Just look at how incomprehensible AGL looping looks > > > > Os := Copy(Start(Deque'Access), Finish(Deque'Access), Os); > > > > or > > > > Pos := Find(Start(IVec'Access), Finish(IVec'Access), 42); > > > > The horror, the horror ... > > > > > The idioms in both languages are completely different. So forget about > > > the STL as a model for an Ada library. ... snip ... > > > > So far, you've said nothing that indicates that you've looked seriously at > > the STL. Why don't you just get very specific and say exactly why you > > think it is a bad model for an Ada library, using examples? I think the > > idea of writing algorithms over collections in terms of their iterators is > > a good one. > > I thought Matthew just did that, but you haven't answered the question > "why does the STL allow iteration past the end of the array". This > bugs me too. Is there a real reason here, or is it an accident of the > implementation? How do you even know that it points past the end of the array, in an Ada implementation? We have a constructor for an iterator called "Last" or "Finish" or whatever. Should it matter how Finish is implemented? > Perhaps it is the most general way to define an iterator that points > to nothing? It is *a* way to define a stopping condition or sentinel value. In the case of a red-black tree, the null pointer is a sentinel. In the case of an array, whose iterator conceptually looks like a pointer-offset pair, an offset one greater than the highest index of the array makes a fine sentinel, and it just so happens that in C++ you can use this easily. > Certainly if the underlying implementation of a collection > is an array, this makes sense. But if the underlying implementation is > a list, then a null pointer makes more sense. Why not make the > abstraction resemble a null pointer, rather than an out-of-bounds > index? In what way does the value of Finish not resemble a null pointer,indeed, when iterating over a list and checking for nullness of a pointer, in what way does that not resemble checking for an out of bounds index? -- Brian