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!news3.google.com!news.glorb.com!wns14feed!worldnet.att.net!216.196.98.141!border2.nntp.dca.giganews.com!nntp.giganews.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: Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:JfEXvm2LYJCuyIKc6jd6+8VHDLc= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 04 Sep 2005 10:26:13 +1000 NNTP-Posting-Host: 61.8.44.238 X-Complaints-To: news@pacific.net.au X-Trace: nasal.pacific.net.au 1125793843 61.8.44.238 (Sun, 04 Sep 2005 10:30:43 EST) NNTP-Posting-Date: Sun, 04 Sep 2005 10:30:43 EST Xref: g2news1.google.com comp.lang.ada:4424 Date: 2005-09-04T10:26:13+10:00 List-Id: Hi Matthew, Thanks for your quick reply to my query! Matthew Heaney writes: > David Trudgett writes: > >> Does anyone know where I can find some usage examples for the Charles >> container library, or some code that makes use of Charles? > > Here's my Ada-Europe 2004 tutorial: > > http://charles.tigris.org/charles_tutorial.ppt > http://charles.tigris.org/charles_tutorial.pdf Yes, I've actually had a look through this slide show, but for me it's usefulness was limited by not having the verbal explanations that go with it! :-) Also, I couldn't find any complete example that includes all the declarations etc. that one needs to get it working. > > My original AI-302 proposal was based on Charles, and contains many > examples: > > http://home.earthlink.net/~matthewjheaney/charles/ai302.txt Yes, a lot of work went into that (extremely long!) text file, and there are no doubt some useful snippets in there, but once again it omits the entire infrastructure that one needs to get something to work (no doubt because it's considered elementary -- except it's not to me! :-)). > > >> I've got Charles downloaded and installed on my include path, but as a >> newcomer to Ada, I'm having difficulty working out how it is intended >> to be used. > > Charles is more or less a port of the STL to Ada95, so if you can follow > an STL tutorial (there are lots of them on the web), then you shouldn't > have any problem extrapolating that to Charles. It's a possibility, but I have no familiarity with C++, and I'm only getting started in Ada, so I think it will be more difficult than you suggest. > > The standard container library has changed significantly from my > original proposal, but even so you should be able to follow the AI-302 > examples: > > http://charles.tigris.org/source/browse/charles/src/ai302/examples/ These may prove to be useful, too, and I have had a look through the hash map related ones. I think I made a bit of progress using these, but they leave me guessing a bit what to "with" and "use", and where. It's seeming to me at the moment that to make a simple data structure consisting of a hash table of lists, I need to instantiate two generic packages (requiring two separate files in GNAT, I assume), work out the necessary WITH and USE clauses, figure out how to declare the containers, and then put the code in to extract the data from the map (for which you've given me a useful hint below, in "PROCEDURE OP"). Of course, in this case, I could certainly use an Ada array instead of the list; and, in fact, I could also use an array instead of a map. But I didn't think it was going to be hard to create and use a map and list in Ada! :-) I'm hoping that it's looking harder than it really is at the moment, simply because I'm not very conversant with Ada generics yet. > > >> The first thing I had in mind to do was to create a simple map, for >> example, to translate the following Common Lisp: >> >> (defvar *side-corners* >> '((2 (1 3)) >> (4 (1 7)) >> (6 (3 9)) >> (8 (7 9)))) > > You can use a map, instantiated with type Integer as the key and an > instantiation of a list as the element. Either the hashed map or the > ordered map would suffice. When I tried to instantiate a hashed map, it seemed to want me to supply a hash function. > > >> This is just a simple mapping of four particular integers (2, 4, 6, 8) >> to four particular lists each consisting of two integers. >> >> I use it in a function like this: >> >> (defun side-corners (side) >> "Return a list of the (two) corners that flank the given side" >> (second (assoc side *side-corners*))) >> >> so that the function call >> >> (side-corners 2) >> >> returns the list (1 3) > > Something like (I have omitted a few steps): > > procedure Op (Map : Container_Type) is > I : constant Iterator_Type := Find (Map, Key => 2); > L : List_Types.Container_Type renames To_Access (I).all; > begin > ... > end; OK, thanks for that. That second line ("L :") is particularly useful. > > This is similar to the C++ code: > > void f(const map_t& m) > { > const map_t::const_iterator i = m.find (2); > const list_t& L = *i; > //... > } Unfortunately, I'm unfamiliar with the STL. :-( But I can see the similarity. > > >> Any pointers to code samples, or other hints would be greatly >> appreciated! > > Send me email (or continue posting to CLA) if you need any help. I'll use the list for now, assuming that others might benefit besides myself. Thanks. David -- David Trudgett http://www.zeta.org.au/~wpower/ Naturally the common people don't want war...but after all it is the leaders of a country who determine policy, and it is always a simple matter to drag the people along.... All you have to do is tell them they are being attacked, and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country. -- Hermann Goering (1893-1946), 1936