comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@acm.nospam.org>
Subject: Re: Containers - nontrivial element access
Date: Wed, 03 Oct 2007 22:02:38 GMT
Date: 2007-10-03T22:02:38+00:00	[thread overview]
Message-ID: <2kUMi.133748$Fc.79421@attbi_s21> (raw)
In-Reply-To: <1191440425.737861.140360@50g2000hsm.googlegroups.com>

Maciej Sobczak wrote:
> 
> Imagine I haven an *array* of Person(s) and I do this:
> 
> Swap (People (X).Salary, People (Y).Salary);
> 
> This is Ada.
> 
> (is it value semantics for you, btw?)
> 
> Now I want to do the same with vector.

You can want to do anything, but that's a good way to be disappointed.

Let's deal with the simpler

People (X).Salary := S;

so we're not mislead by the call to Swap.

With an array, there are no operations (subprograms or entries) invoked. 
With a data structure, you must invoke an operation to get at a value 
stored in it. That's what causes the difference. The operations on the 
data structure return values, so modifying them does not change the 
value stored in the data structure.

> In other words, I want to use Ada in the Ada spirit.

No, the Ada spirit is generally to deal with values (as Ada.Containers 
does), not anonymous references, as is common in C/++ and the STL (since 
everything in C/++ is aliased), though one could argue that the addition 
of anonymous access types and values in Ada 95, and its expansion in Ada 
07 (things I don't like; pointers should be as difficult to use as 
possible), changes the spirit.

> If we realize that vector is a generalization of array, is it
> revolutionary to expect that the common functionality should have
> common interface?

If we realize that package Ada.Containers.Vectors is an 
unbounded-sequence data structure (as is Doubly_Linked_Lists), then we 
would not expect anything of the kind. There are hints in the discussion 
and some of the operations that Vectors is intended specifically for an 
array implementation, but an implementation built on top of 
Doubly_Linked_Lists would be perfectly legal and correct. There are 
analogs of array operations, but they are only analogs.

Ada.Containers is quite general and as safe as possible; it is unlikely 
to be appropriate for many applications. It may be that you should write 
your own, with "access Element" prevalent, for your specific needs. If 
not, you'll have to use the syntax and semantics of the existing packages.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53



  parent reply	other threads:[~2007-10-03 22:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-01 21:55 Containers - nontrivial element access Maciej Sobczak
2007-10-01 23:52 ` Alex R. Mosteo
2007-10-02 16:40   ` Matthew Heaney
2007-10-02 23:16     ` Alex R. Mosteo
2007-10-02 20:47   ` Maciej Sobczak
2007-10-02 23:23     ` Alex R. Mosteo
2007-10-02  0:39 ` Jeffrey R. Carter
2007-10-02 16:44   ` Matthew Heaney
2007-10-03  0:20     ` Jeffrey R. Carter
2007-10-03 19:40       ` Maciej Sobczak
2007-10-03 19:56         ` Matthew Heaney
2007-10-03 20:21           ` Dmitry A. Kazakov
2007-10-03 22:37             ` Matthew Heaney
2007-10-04  8:06               ` Dmitry A. Kazakov
2007-10-03 22:02         ` Jeffrey R. Carter [this message]
2007-10-04  0:16         ` Robert A Duff
2007-10-07  8:41           ` Jacob Sparre Andersen
2007-10-11 19:15             ` Robert A Duff
2007-10-14  4:59               ` Jacob Sparre Andersen
2007-10-14  7:24                 ` Dmitry A. Kazakov
2007-10-14 13:49                   ` Georg Bauhaus
2007-10-14 15:07                     ` Dmitry A. Kazakov
2007-10-02 20:50   ` Maciej Sobczak
2007-10-03  0:22     ` Jeffrey R. Carter
2007-10-03  8:26       ` Dmitry A. Kazakov
2007-10-03 18:49         ` Jeffrey R. Carter
2007-10-03 19:09           ` Matthew Heaney
2007-10-03 19:15           ` Simon Wright
2007-10-03 19:48             ` Maciej Sobczak
2007-10-03 19:58             ` Matthew Heaney
2007-10-03 19:35           ` Dmitry A. Kazakov
2007-10-02  2:34 ` Randy Brukardt
2007-10-02 16:47   ` Matthew Heaney
2007-10-02  7:23 ` Dmitry A. Kazakov
2007-10-02 16:37 ` Matthew Heaney
2007-10-02 21:02   ` Maciej Sobczak
2007-10-02 22:20     ` Matthew Heaney
2007-10-03 19:59       ` Maciej Sobczak
2007-10-03 22:55         ` Matthew Heaney
2007-10-04  0:22         ` Robert A Duff
2007-10-04 13:01         ` Georg Bauhaus
2007-10-04 14:01           ` Matthew Heaney
2007-10-04 21:58           ` Matthew Heaney
replies disabled

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