comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <mheaney@on2.com>
Subject: Re: OO Style with Ada Containers
Date: Mon, 19 Nov 2007 07:51:32 -0800 (PST)
Date: 2007-11-19T07:51:32-08:00	[thread overview]
Message-ID: <a13459f0-13d9-4f7d-a619-c28dd8c4e869@f3g2000hsg.googlegroups.com> (raw)
In-Reply-To: f035a11d-1a56-480e-a577-502217b5c7b3@w34g2000hsg.googlegroups.com

On Nov 19, 8:44 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> On 19 Lis, 03:53, Matthew Heaney <matthewjhea...@earthlink.net> wrote:
>
> Can you convince me that Ada.Containers is closer to STL than to Java
> containers (for example)?

But the burden of proof is on you, to prove that the container library
is *not* closer to the C++ than it is to the Java containers!  (And
since I know C++ but not Java, such a proof would indeed be
interesting!)


> If not, then why it is repeated so often
> that Ada.Containers were influenced by STL?

You can read my original library proposal here:

http://home.earthlink.net/~matthewjheaney/charles/ai302.txt

As I stated then:

"This library API is modeled on the STL.  It has the same containers
as
the STL does, using the same container names and semantics.  If you
know
the STL already then you will instantly understand how this library
works.  It does not have any of the STL algorithms, but that's only
because I wanted to keep the API small (and not because it's not
possible to support STL-style algorithms -- it is).  The API described
here has exactly the minimum set of containers I believe all Ada
developers need, in exactly the form they need it."


> Do you by any chance find
> something in C++ that is worth imitating? :-)

Yes, of course: the STL.


> I don't claim that the designers of Ada.Containers didn't have STL in
> mind when taking some decisions, but the essence [*] of STL just
> didn't get there.

Well, the library is modeled on the STL.  There are necessarily
differences, because the languages are different, and my design
philosophy was (and is) to use Ada idioms where appropriate.


> >  Ada has other mechanisms, such as nested procedures and
> > downward closures, and the container library was designed to use the Ada
> > mechanisms.
>
> How can I use these mechanisms to make iterator adaptors?

A generic algorithm in Ada would look something like:

generic
   type Cursor is private;
   with function Next (C : Cursor) return Cursor is <>;
   with function Has_Element (C : Cursor) return Boolean is <>;
   ...
procedure Generic_Algorithm (C : Cursor);

You can instantiate this on the container types directly, e.g.

package Integer_Vectors is new Vectors (Integer);
use Integer_Vectors;

procedure Algorithm is new Generic_Algorithm (Cursor);

This instantiation will deliver every integer element in the vector.
An iterator adapter just means replacing the cursor operations for the
container with something else, e.g.

function Return_Odd_Only (C : Cursor) return Cursor is
  CC : Cursor := C;

begin
  while Has_Element (CC)
    and then Element (CC) rem 2 = 0
  loop
     Next (CC);
  end loop;
  return CC;
end Return_Odd_Only;

procedure Algorithm is
  new Generic_Algorithm
  (Cursor,
   Next => Return_Odd_Only,
   others => <>);  -- verify syntax

procedure Op (V : Vector) is
begin
   Algorithm (V.First);
end;


> Consider a
> filtering iterator that automatically skips unwanted (for the given
> predicate) elements.

See above for an example.


> Consider a virtual iterator that does not have
> *any* container behind, but can serve as a sequence generator. And so
> on.

But the generic algorithms depend only on a cursor as a generic formal
-- the algorithms aren't tied to containers directly (which was
Stepanov's great insight).  For example, let's use the algorithm above
with an array:

type Integer_Array is (Positive range <>) of Integer;
-- the "container" type

procedure Op (A : Integer_Array) is
   function Has_Element (J : Integer) return Boolean is
   begin
      return J <= A'Last;
   end;

   procedure Algorithm is
     new Generic_Algorithm
     (Cursor => Integer,
      Next   => Integer'Succ);

begin
   Algorithm (A'First);
end;




  parent reply	other threads:[~2007-11-19 15:51 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-14 23:28 OO Style with Ada Containers braver
2007-11-14 23:50 ` Adam Beneschan
2007-11-14 23:59   ` braver
2007-11-15  0:24     ` braver
2007-11-15  9:36       ` Ludovic Brenta
2007-11-15 10:36         ` braver
2007-11-15 11:35           ` Ludovic Brenta
2007-11-15 13:50             ` braver
2007-11-19  2:45               ` Matthew Heaney
2007-11-15 18:22             ` braver
2007-11-15 20:18               ` Ludovic Brenta
2007-11-19  2:48                 ` Matthew Heaney
2007-11-19  2:47               ` Matthew Heaney
2007-11-19  2:39             ` Matthew Heaney
2007-11-19  2:38           ` Matthew Heaney
2007-11-19  2:36         ` Matthew Heaney
2007-11-19  2:24       ` Matthew Heaney
2007-11-23 10:28         ` braver
2007-11-23 13:29           ` Martin Krischik
2007-11-23 14:19             ` Georg Bauhaus
2007-11-25 13:38           ` Ludovic Brenta
2007-11-26  3:58             ` Matthew Heaney
2007-11-26  3:55           ` Matthew Heaney
2007-11-23 22:25         ` braver
2007-11-23 22:46           ` Pascal Obry
2007-11-23 22:52             ` braver
2007-11-26  4:09               ` Matthew Heaney
2007-11-26  4:07             ` Matthew Heaney
2007-11-26  4:03           ` Matthew Heaney
2007-11-26 13:45             ` Matthew Heaney
2007-11-26 19:09               ` braver
2007-11-26 20:29                 ` Matthew Heaney
2007-11-27 19:31                   ` Georg Bauhaus
2007-11-27 20:12                     ` Matthew Heaney
2007-11-25 14:08         ` braver
2007-11-26  4:21           ` Matthew Heaney
2007-11-19  1:04   ` Matthew Heaney
2007-11-15  8:43 ` Dmitry A. Kazakov
2007-11-15 14:04   ` Maciej Sobczak
2007-11-19  2:53     ` Matthew Heaney
2007-11-19 13:44       ` Maciej Sobczak
2007-11-19 14:44         ` Martin
2007-11-19 15:51         ` Matthew Heaney [this message]
2007-11-19 17:33           ` Markus E L
2007-11-19 21:29           ` Maciej Sobczak
2007-11-19 22:16             ` Matthew Heaney
2007-11-19 22:22               ` Matthew Heaney
2007-11-20 14:11               ` Maciej Sobczak
2007-11-20 17:00                 ` Matthew Heaney
2007-11-20 17:17                   ` Matthew Heaney
2007-11-20 21:13                   ` Maciej Sobczak
2007-11-20 21:57                     ` Matthew Heaney
2007-11-21  4:51                     ` Matthew Heaney
2007-11-21  9:18                       ` Georg Bauhaus
2007-11-21 15:59                         ` Maciej Sobczak
2007-11-21 17:41                           ` Georg Bauhaus
2007-11-21 22:25                         ` Jeffrey R. Carter
2007-11-20 18:06                 ` Georg Bauhaus
2007-11-19 16:19         ` Dmitry A. Kazakov
2007-11-19 20:45           ` Maciej Sobczak
2007-11-20  2:24             ` Matthew Heaney
2007-11-20  9:06             ` Dmitry A. Kazakov
2007-11-20 12:16               ` Georg Bauhaus
2007-11-21 15:17                 ` Dmitry A. Kazakov
2007-11-19  2:50   ` Matthew Heaney
2007-11-19  1:03 ` 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