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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,70414f56d810c10c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!feeder.news-service.com!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: discriminant questions Date: Fri, 23 Sep 2011 09:59:33 +0200 Organization: cbb software GmbH Message-ID: References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> <01a1374f-59ab-40be-9e39-0640cb2a513d@n35g2000yqf.googlegroups.com> <1fp2o673mu9az$.d9loz1zbcl0d.dlg@40tude.net> <14tiipigyejtc$.hyp7e82egqwq$.dlg@40tude.net> <34d856bd-19a3-4bbf-b9d8-c0f100000ef4@k7g2000vbd.googlegroups.com> <1tpl2pc36ptr4$.txv4v3wmkjlm.dlg@40tude.net> <1malv6h6q31j3.uz9ws5j0glnm.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news1.google.com comp.lang.ada:21073 Date: 2011-09-23T09:59:33+02:00 List-Id: On Thu, 22 Sep 2011 13:57:51 -0700 (PDT), Maciej Sobczak wrote: > On Sep 22, 10:07�am, "Dmitry A. Kazakov" > wrote: > >> Consider a generic >> implementation of removing all elements of the container using iterators: >> >> � �This := Container.First; >> � �while This /= Null_Iterator loop >> � � � �Next := This.Next; >> � � � �This.Delete; >> � � � �This := Next; >> � �end loop; >> >> This may work or not depending on the semantics of Delete. E.g. for a >> circular list, it will loop forever. > > Not convincing, for several reasons: > > 1. Null_Iterator as a sentinel value is not necessary, you might use > Container.Is_Empty instead. Is_Empty is a container-wide operation. X = Null_Iterator is an iterator operation, same is X.Is_In. Aren't you a proponent of iterator approach? > 2. Even with the above structure, This := This.Delete_And_Move_To_Next > would do the trick. It would also work for vectors. What about This.Delete? Should it be removed from the interface? The problem here is the semantics of existing iterators upon container manipulation, not computability of the algorithm. Iterators as pointers have issues that operations on other pointers influence pointers apparently not involved in the operation, while the implied contract of an iterator is that it points its element no matter what. Can I declare an iterator object constant? What is the meaning of its "constantness" when the container gets manipulated? See a huge language problem here? An iterator can be immutable only if the container is. How do I express such stuff in the language? > 3. You don't have to include circular lists in the same set of types > as other linear containers in the first place, so there would be no > temptation to use the generic algorithm with inappropriate container. > That is, a circular list probably deserves a different interface > anyway. Circular lists are the most important ones among doubly-linked lists, and are especially interesting for iterator-based approaches, because insertion and removal in such lists can be done without knowing the list's head. > 4. Are you sure that the circularity is a property of the container? And being doubly linked is? That is the whole point, list of whatever structure is not yet a container. > Or rather of the traversal? Do you know that I can write a circular > iterator as a wrapper for a "normal" one, for any linear container? > Will you insist on having a completely separate container type for > backwards/randomized/etc. iteration as well? Now you are closer to understanding my point that list is not a container and the interface of container is not necessarily its implementation. > So you are blaming iterators for having badly designed generic > container interface in the first place. Not convincing. There are more comfortable and safe interfaces than iterators, I want them available first. I want the language supporting implementation of such interfaces rather than mounting kludges on kludges like accessors, limited returns etc. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de