comp.lang.ada
 help / color / mirror / Atom feed
From: David Trudgett <wpower@zeta.org.au.nospamplease>
Subject: Re: Charles container library usage examples
Date: Tue, 06 Sep 2005 13:01:03 +1000
Date: 2005-09-06T13:01:03+10:00	[thread overview]
Message-ID: <m31x42rjbk.fsf@rr.trudgett> (raw)
In-Reply-To: 87mzmssqbq.fsf@ludovic-brenta.org

Hi Ludovic,

Ludovic Brenta <ludovic@ludovic-brenta.org> writes:

> David, in the past I also played with Charles and instantiated a
> hashed map of Unbounded_Strings, which I used to represent the headers
> in an email, and then a List_Of_Regexes.  You might be interested in
> how I did the instantiations:

Yes, those were very useful to me. I had already got to the stage of
trying this syntax:

> package Lists_Of_Regexes is
>    new Charles.Vectors.Unbounded (Index_Type => Positive,
>                                   Element_Type => Unbounded_String);

but your examples showed me that I was on the right track! What I
ended up with was:

----------------------------------------
-- file: side_corners_map.ads
with Charles.Maps.Sorted.Unbounded;
with Corner_List; use Corner_List;

package Side_Corners_Map is
   new Charles.Maps.Sorted.Unbounded (Key_Type => Integer,
                                      Element_Type => Corner_Pair);


----------------------------------------
-- file: corner_list.ads
package Corner_List is

   subtype Corner is Integer;
   subtype Pair is Integer range 1 .. 2;
   type Corner_Pair is array (Pair) of Corner;

end Corner_List;


----------------------------------------
-- file: class_board.ads
with Ada.Strings.Unbounded, Ada.Finalization, Side_Corners_Map;
use Ada.Strings.Unbounded, Ada.Finalization;

...

private

...

   Side_Corners : Side_Corners_Map.Container_Type;


----------------------------------------
-- file: class_board.adb
with Side_Corners_Map, Corner_List;
use Side_Corners_Map, Corner_List;

package body Class_Board is


   procedure Initialize (Self : in out Board) is
      Top    : Corner_Pair := (1, 3);
      Left   : Corner_Pair := (1, 7);
      Right  : Corner_Pair := (3, 9);
      Bottom : Corner_Pair := (7, 9);
   begin
      Reset(Self);
      Insert(Side_Corners, 2, Top);
      Insert(Side_Corners, 4, Left);
      Insert(Side_Corners, 6, Right);
      Insert(Side_Corners, 8, Bottom);
   end Initialize;



You can see I ditched the list for a simple array! I already had more
punishment than I cared for! ;-) I sort of don't mind going to this
much trouble for the advantages that Ada can give me over, say, Lisp
(which is what I'm translating from) in terms of execution speed, low
level control, native concurrency, etc. etc., but it *is* a fair bit
to replace five lines of unremarkable Lisp! :-) I was thinking that
the elaborateness of all this must provide a powerful disincentive for
Ada programmers to use collections/containers. Of course, if you
really need a collection, then you'll need to go to the trouble to
have one; but I'm thinking that there must be a whole lot of in
between cases where, although you can just get by with, say, arrays,
records, classes, even home-grown linked lists, and so on, it really
would be better to use the appropriate data structure and
algorithms. Anyway, that's just me daydreaming. Perhaps someone might
have something actually sensible to say about these thoughts.

I do have a couple of little questions about the code that I came up
with:

1. Is my INITIALIZE procedure more verbose than it needs to be? I
   wanted to put the array definitions inside the call to INSERT, but
   I don't think that's possible.

2. Did I need the separate file "corner_list.ads"? I tried to put it
   in "side_corners_map.ads", but the compiler didn't seem to like
   that idea.


Thanks,

David


-- 

David Trudgett
http://www.zeta.org.au/~wpower/

    Viking, n.:

    1. Daring Scandinavian seafarers, explorers, adventurers,
       entrepreneurs world-famous for their aggressive, nautical 
       import business, highly leveraged takeovers and blue eyes.
    
    2. Bloodthirsty sea pirates who ravaged northern Europe 
       beginning in the 9th century.

    Hagar's note: The first definition is much preferred; the 
    second is used only by malcontents, the envious, and disgruntled 
    owners of waterfront property.



  reply	other threads:[~2005-09-06  3:01 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-03  2:38 Charles container library usage examples David Trudgett
2005-09-03  5:15 ` Matthew Heaney
2005-09-03  9:45   ` Simon Wright
2005-09-04  6:25     ` David Trudgett
2005-09-05 11:28       ` Georg Bauhaus
2005-09-04  0:26   ` David Trudgett
2005-09-04  9:49     ` Matthew Heaney
2005-09-06  3:01       ` David Trudgett
2005-09-06 16:22         ` Jeffrey Carter
2005-09-07  0:15         ` Matthew Heaney
2005-09-04 17:19     ` Ludovic Brenta
2005-09-06  3:01       ` David Trudgett [this message]
2005-09-06  5:08         ` Ludovic Brenta
2005-09-06  6:46           ` David Trudgett
2005-09-06  7:26             ` Ludovic Brenta
2005-09-24  0:05               ` Randy Brukardt
2005-09-09 14:57         ` James Alan Farrell
2005-09-10  7:38           ` David Trudgett
2005-09-10 14:55             ` Matthew Heaney
2005-09-10 15:26               ` Ludovic Brenta
2005-09-10 17:58                 ` Matthew Heaney
2005-09-12  0:24               ` Robert A Duff
2005-09-11 10:52             ` Georg Bauhaus
2005-09-11 21:14               ` David Trudgett
2005-09-13 23:41                 ` Björn Persson
2005-09-14  6:39                   ` David Trudgett
2005-09-12  0:21             ` Robert A Duff
2005-09-12  0:57               ` David Trudgett
2005-09-12  1:01                 ` Robert A Duff
replies disabled

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