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=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:298b:: with SMTP id p133mr5880868itp.43.1553349576704; Sat, 23 Mar 2019 06:59:36 -0700 (PDT) X-Received: by 2002:aca:61d6:: with SMTP id v205mr509100oib.122.1553349576293; Sat, 23 Mar 2019 06:59:36 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!78no277584itl.0!news-out.google.com!l81ni335itl.0!nntp.google.com!w126no277291ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 23 Mar 2019 06:59:35 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: <6e1977a5-701e-4b4f-a937-a1b89d9127f0@googlegroups.com> <6f9ea847-2903-48c8-9afc-930201f2765a@googlegroups.com> <74339f3f-9591-45a3-8632-8834b4b466ab@googlegroups.com> <5be8a4cc-84de-4716-9f0c-10907f451312@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <735761d5-f917-4477-9b0a-e0cde1ce2440@googlegroups.com> Subject: Re: Intervention needed? From: Jere Injection-Date: Sat, 23 Mar 2019 13:59:36 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:55938 Date: 2019-03-23T06:59:35-07:00 List-Id: On Saturday, March 23, 2019 at 3:53:34 AM UTC-4, Randy Brukardt wrote: > "Jere" wrote in message > ... > > Not really. In Rust they don't even use cursors. They go straight to > > iterators. On top of that, the combination of being able to specify the > > lifetime of all of your variables (if you need to) and the ownership rules > > gives them 100% safety from dangling references when they create and use > > those iterators. > > If you don't store any cursors and just use iterators in Ada, you have the > same level of safety: the tampering checks prevent any problems with > iterators. (Well, unless you turn them off, of course, but if you remove the > seatbelts, you can't much complain that they didn't protect you.) > > I'd be interested to find out how Rust deals with the need to designate > individual elements of a container (which is the primary reason that Ada > exposes cursors). > > Randy. Keep in mind the rust paradigm is very different than Ada's. When you obtain an iterator of a container, you borrow ownership of the container. At that point it is impossible to tamper with the container because it is a compile time error to modify the container when something else has ownership of it. It's a compile time version of Ada's tampering checks using an ownership model. If you need to remove items as you iterate, there is a consuming version of the iterator that allows for that. It handles all the logic of keeping the iterator correct as you remove items. If you need to remove only specific items, it provides functions for that as well (but you would not iterate while using them do to the ownership/borrowing rules). Additionally, Rust allows you to specify the lifetime of the iterator, the lifetime of the reference to the item, and how they relate to the lifetime of the container so that the compiler can guarantee that nothing dangles (it's a relative specification..container has lifetime A and everything else has either A or a lifetime relative to A). If you were instead referring to indexing the container, for things like vector, Rust looks to see if the container implements the Index trait, and, if so, allows for the user to use the index operation on the container. It's very similar to making a cursor and setting the variable_indexing aspect and constant_indexing aspect, except rust doesn't expose the underlying equivalent cursor type. So you either work with Indexes or Iterators depending on your need.