comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Intervention needed?
Date: Wed, 27 Mar 2019 17:48:30 -0700 (PDT)
Date: 2019-03-27T17:48:30-07:00	[thread overview]
Message-ID: <5869cc6b-dd17-47dd-bdfb-f6987cff6402@googlegroups.com> (raw)
In-Reply-To: <q7b9at$q5q$2@franka.jacob-sparre.dk>

On Monday, March 25, 2019 at 3:14:38 PM UTC-4, Randy Brukardt wrote:
> "Jere" wrote in message
> > On Saturday, March 23, 2019 at 3:53:34 AM UTC-4, Randy Brukardt wrote:
> ...
> > 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.
> 
> I was specifically asking about the common need to have connections between
> containers. It's not likely that a single container is all one needs to
> solve a problem, so one needs ways to refer to elements of one container
> from another.
> 
> For instance, one might need a index for another container. (For instance,
> to allow lookups by some internal characteristic.) If the main container is
> structured (as in an internal representation of HTML or XML, or a compiler
> symbol table), the index has to be a separate container. Ada provides
> cursors to represent those sorts of interconnections. How does Rust do it??
> (If it does it at all.)
> 
> This sort of thing comes up any time that one has two separate data
> structures that are inter-related. Sometimes you can use composition for
> combining structures (and that's preferable when possible), but if there are
> potentially multiple references to a single item or if the element is just
> part of a larger data structure, composition doesn't work and some sort of
> reference is needed.
> 
>                        Randy.
> 
> P.S. Sorry about breaking the thread; the message wouldn't post because of 
> header limits (too many replies).

I generally don't come across situations that require this, so I don't know
how useful my answer will be.  Plus I've only programmed in Rust off and on
for fun on some side projects.  I mostly do either C or Ada as the platform
allows.

Generally, Rust looks at potential memory erroneous access as a 100% no
no, so the same method used in Ada with Cursors wouldn't be allowed.  They
have really really low chance, but there still is a chance.  From what
I could find on the topic, the general first suggestion is to rethink
your approach and pick a better solution that doesn't involve potentially
dangling references (similar to the mentality we often suggest to new
comers trying to port ideas from C/C++ into Ada directly without 
considering the Ada way).  

Aside from that, if you can't approach it very differently, there are
different options available.  For more temporary type situations (say
wanting to delete a subset of elements from a container), they provide
various map(), filter(), and collect() operations that interact with
the iterators to get the configuration you want.

For more long term containers (This sounds more like what you are asking
for), the methods I came across were to take a step back and determine
which of the 2 (or more) containers really needs to be the owner of the
data (it isn't always the one that common sense initially indicates), 
have it own the data using an owning reference, and have the other
containers use non-owning references (which you can promote to owning
references temporarily as needed).  That would be more along the lines
of the idiomatic "safe" approach.  This allows Rust to keep track
of who can use the reference when (using temporal rules) and doesn't 
involve any unsafe code.

That isn't a silver bullet for all situations though.  In some cases, 
you might have to use one standard container and another that you 
make from scratch and have the standard container integrate into the 
other one under the hood. 

I'm not a very seasoned Rust programmer, so I am probably missing some
other solutions.  I'm more comfortable in Ada and like to use it more
anyways.  I'm also sure you could come up with some situation where
the above suggestions wouldn't work.   I don't generally have a better
answer due to lack of experience.  And the answer may at some point
indeed involve unsafe programming. You are still required to maintain
the 100% memory safety, even in the case of using the "unsafe" keyword,
so something too similar to the Ada cursors method in its current form
would not be allowed.

Sorry for the long wait on the reply.  I wanted to do some test programming
to make sure the stuff I mentioned above would actually work and also
do some research on it since, in my problem domains, I don't ever run
into situations where container shadowing/interacting is required.

  parent reply	other threads:[~2019-03-28  0:48 UTC|newest]

Thread overview: 146+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 19:14 Intervention needed? Randy Brukardt
2019-03-25 20:44 ` Dmitry A. Kazakov
2019-03-28  0:48 ` Jere [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-04-02 22:07 Randy Brukardt
2019-04-03  7:29 ` Dmitry A. Kazakov
2019-04-03 14:31   ` Optikos
2019-04-03 14:54     ` Dmitry A. Kazakov
2019-04-03 15:29       ` Optikos
2019-04-03 16:16       ` Simon Wright
2019-04-03 17:15         ` Dmitry A. Kazakov
2019-04-03 21:12           ` Simon Wright
2019-04-04  7:09             ` Dmitry A. Kazakov
2019-04-04  5:44           ` Maciej Sobczak
2019-04-04  7:17             ` Dmitry A. Kazakov
2019-04-04  7:22             ` Paul Rubin
2019-04-04  8:37               ` Niklas Holsti
2019-04-05  0:13                 ` Randy Brukardt
2019-04-05  5:45                 ` Maciej Sobczak
2019-04-05 15:17                   ` Optikos
2019-04-06  1:38                     ` Jere
2019-04-06  4:25                       ` alby.gamper
2019-04-06  6:49                         ` Jere
2019-04-06  8:24                           ` alby.gamper
2019-04-04 12:28             ` Simon Wright
2019-04-04 16:17           ` Optikos
2019-04-03 15:07 ` Lucretia
2019-04-03 16:15   ` Simon Wright
2019-04-03 17:23 ` Niklas Holsti
2019-04-03 17:48   ` Bill Findlay
2019-04-03 21:01   ` Simon Wright
2019-04-03 18:58 ` Dennis Lee Bieber
2019-03-08 16:43 Olivier Henley
2019-03-08 16:58 ` Dmitry A. Kazakov
2019-03-08 17:31 ` gautier_niouzes
2019-03-11 14:31   ` antispam
2019-03-11 15:07     ` gautier_niouzes
2019-03-11 17:19     ` Dmitry A. Kazakov
2019-03-11 15:34 ` Lucretia
2019-03-11 17:30   ` Simon Wright
2019-03-11 17:42     ` Dmitry A. Kazakov
2019-03-11 18:14       ` AdaMagica
2019-03-11 19:52   ` Olivier Henley
2019-03-11 20:04     ` Lucretia
2019-03-11 22:08   ` Jeffrey R. Carter
2019-03-12  2:04     ` Lucretia
2019-03-12 13:17       ` Olivier Henley
2019-03-12 16:32       ` Jeffrey R. Carter
2019-03-12 16:56         ` Lucretia
2019-03-12 17:20           ` Lucretia
2019-03-12 18:14         ` Olivier Henley
2019-03-12 19:21           ` Lucretia
2019-03-12 21:53             ` Randy Brukardt
2019-03-13 10:50               ` Jere
2019-03-17 12:52               ` Optikos
2019-03-17 16:37                 ` Luke A. Guest
2019-03-17 16:48                 ` Paul Rubin
2019-03-20  0:49                   ` Optikos
2019-03-20  1:04                     ` Paul Rubin
2019-03-20  1:19                       ` Optikos
2019-03-18 23:36                 ` Randy Brukardt
2019-03-19  2:18                   ` Optikos
2019-03-19  8:44                     ` Dmitry A. Kazakov
2019-03-19  9:53                       ` Optikos
2019-03-19 22:13                         ` Randy Brukardt
2019-03-19 22:26                           ` Paul Rubin
2019-03-20  1:08                             ` Jere
2019-03-22  2:26                               ` Randy Brukardt
2019-03-23 15:56                                 ` Jeffrey R. Carter
2019-03-23 21:38                                   ` Paul Rubin
2019-03-19 22:36                           ` Optikos
2019-03-19 23:13                             ` Randy Brukardt
2019-03-20  1:28                               ` Jere
2019-03-20  8:42                                 ` Dmitry A. Kazakov
2019-03-22  2:00                                 ` Randy Brukardt
2019-03-22 11:10                                   ` Jere
2019-03-23  8:03                                     ` Randy Brukardt
2019-03-23 21:32                                       ` Jere
2019-03-20  7:59                               ` Optikos
2019-03-22  2:16                                 ` Randy Brukardt
2019-03-22  8:38                                   ` Optikos
2019-03-22 10:54                                     ` Jere
2019-03-23  7:53                                       ` Randy Brukardt
2019-03-23 13:59                                         ` Jere
2019-03-23 21:19                                           ` Jere
2019-03-23 21:29                                             ` Paul Rubin
2019-03-26  8:09                                           ` Optikos
2019-03-20  1:20                           ` Jere
2019-03-22  2:30                             ` Randy Brukardt
2019-03-22  9:08                               ` Dmitry A. Kazakov
2019-03-22 22:23                                 ` Optikos
2019-03-27 19:20                                   ` G. B.
2019-03-27 21:02                                     ` Paul Rubin
2019-03-28  7:01                                       ` Maciej Sobczak
2019-03-28  7:17                                         ` Paul Rubin
2019-03-28  8:39                                           ` Simon Wright
2019-03-30  4:31                                             ` Paul Rubin
2019-03-30 22:14                                           ` Robert A Duff
2019-03-30 22:55                                             ` Paul Rubin
2019-03-28  9:06                                         ` Dmitry A. Kazakov
2019-03-28 20:48                                           ` G. B.
2019-03-29  5:13                                             ` Bojan Bozovic
2019-03-29  8:13                                               ` Dmitry A. Kazakov
2019-03-29  6:57                                           ` Maciej Sobczak
2019-03-29  7:13                                             ` Paul Rubin
2019-03-29  8:39                                             ` Dmitry A. Kazakov
2019-04-01 15:13                                               ` Optikos
2019-04-01 16:51                                                 ` Dmitry A. Kazakov
2019-04-01 21:42                                                   ` Randy Brukardt
2019-04-02  8:30                                                     ` Dmitry A. Kazakov
2019-04-02 15:53                                                       ` Anh Vo
2019-03-19 22:04                       ` Randy Brukardt
2019-03-19 22:22                         ` Paul Rubin
2019-03-19 23:01                           ` Randy Brukardt
2019-03-19  9:37                     ` Optikos
2019-03-19 22:21                       ` Randy Brukardt
2019-03-29 17:56                   ` Florian Weimer
2019-03-29 22:17                     ` Randy Brukardt
2019-03-29 22:35                       ` Florian Weimer
2019-04-01 21:17                         ` Randy Brukardt
2019-03-29 17:41               ` Florian Weimer
2019-03-29 22:16                 ` Randy Brukardt
2019-03-29 22:43                   ` Florian Weimer
2019-04-01 21:29                     ` Randy Brukardt
2019-04-01 22:14                       ` Simon Wright
2019-04-02 21:55                         ` Randy Brukardt
2019-04-04 15:07                           ` Simon Wright
2019-03-12 21:41         ` Randy Brukardt
2019-03-13  9:10     ` Maciej Sobczak
2019-03-13 11:08       ` Jere
2019-03-13 11:11         ` Jere
2019-03-13 11:59         ` Jere
2019-03-13 13:44       ` Olivier Henley
2019-03-13 15:56         ` Simon Wright
2019-03-13 16:25           ` Olivier Henley
2019-03-14  0:40             ` Simon Wright
2019-03-13 16:27           ` Olivier Henley
2019-03-14 22:41         ` Randy Brukardt
2019-03-16 21:30           ` Olivier Henley
2019-03-29 17:38     ` Florian Weimer
2019-03-13 13:23 ` Olivier Henley
2019-03-22 11:10 ` Lucretia
2019-03-22 14:09   ` J-P. Rosen
2019-03-22 16:41   ` Jeffrey R. Carter
2019-03-22 17:29     ` Paul Rubin
2019-03-22 22:36       ` Optikos
2019-04-01  7:28 ` gautier_niouzes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox