Re: Charles container library usage examples



Hi Ludovic,

Ludovic Brenta <ludovic@xxxxxxxxxxxxxxxxxx> 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.
.



Relevant Pages

  • Re: [opensuse] Problem with X after update.
    ... Hello again David. ... You can try running sax2 either from the command line as root or from Yast. ... In most cases, if you have mucked up a specific package by version number, by update from a foreign repository, etc., what you will want to do first is: ... If you have no luck there, then it is time to consider a --force install: ...
    (SuSE)
  • Re: fs: pole position, bz, legend of kage, konami basketball, main event pcbs
    ... Okay, I received a package from "David Zarala", but it only ... I've sent a message to David on my issues with this deal; ... John Hermann wrote: ... I should be receiving the package tomorrow; ...
    (rec.games.video.arcade.collecting)
  • Re: Whats the status of Seaside on D6
    ... Guys if we could work out easy ways to seamlessly import Squeak files that ... David could STS allow ... > the Zip Files package. ... > BTW, in your goodies page, the header of TarFile Tree Model says "ZipFile ...
    (comp.lang.smalltalk.dolphin)
  • Re: Application Rename
    ... Thanks David but I tried making these changes. ... I changed the name of the Unix Executable File in the ... the only occurrences of the app name in the package. ... Do you know why the Duplicate command of the Finder doesn't make the ...
    (comp.sys.mac.programmer.tools)
  • Re: The next number that is not in an array
    ... begun to really dig in to Ruby. ... My first take on this 'quiz' was to initialize a new array with members ... Rails training from David A. Black and Ruby Power and Light: ...
    (comp.lang.ruby)