From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,80435549e92d4e0c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!newsfeed-east.nntpserver.com!nntpserver.com!newsfeed-west.nntpserver.com!news1.optus.net.au!optus!newsfeeder.syd.optusnet.com.au!news.optusnet.com.au!newsfeed.pacific.net.au!nasal.pacific.net.au!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Charles container library usage examples From: David Trudgett Organization: Very little? References: <87mzmssqbq.fsf@ludovic-brenta.org> Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:0XccozFsLfTh6Gaupbg9XeRmsM4= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 06 Sep 2005 13:01:03 +1000 NNTP-Posting-Host: 61.8.33.77 X-Complaints-To: news@pacific.net.au X-Trace: nasal.pacific.net.au 1125975935 61.8.33.77 (Tue, 06 Sep 2005 13:05:35 EST) NNTP-Posting-Date: Tue, 06 Sep 2005 13:05:35 EST Xref: g2news1.google.com comp.lang.ada:4459 Date: 2005-09-06T13:01:03+10:00 List-Id: Hi Ludovic, Ludovic Brenta 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.