comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: OO Style with Ada Containers
Date: Mon, 26 Nov 2007 03:55:05 +0000
Date: 2007-11-26T03:55:05+00:00	[thread overview]
Message-ID: <ubq9hu0di.fsf@earthlink.net> (raw)
In-Reply-To: 1e331441-6abc-4e32-b900-404aa3b10644@g21g2000hsh.googlegroups.com

braver <deliverable@gmail.com> writes:

> A few questions about your solution:
>
> --STX
>
> -- I sense this allows to unroll a blob of Ada compilation units into
> one unit per file, which tool reads this and does it?

gnatchop can extract the ada program units from a single text file.  Save the
post as a text file, remove everything up to (and including) the line "--STX",
and then run gnatchop on the resulting file.


> What's the tradeoff between your solution, using
>
>    package Map_Types is new Indefinite_Hashed_Maps
>      (String,
>       Natural,
>       Hash_Case_Insensitive,
>       Equal_Case_Insensitive);
>
> -- and Ludivoc Brenta's, using Hashed_Sets of your modified
> discriminated
>
>    type Word_Counter (Length : Positive) is record
>       Word  : String (1 .. Length);
>       Count : Natural;
>    end record;

It depends on whether you want to use a map or a set.  I don't see any
substantive difference here (well, I think a map is a more natural fit for your
problem), so if you're not sure then just use a map.

If you do use a set (again, try it, as it makes a nice exercise for learning
the library), then there's no reason to use Unbounded_String when a
discriminanted record will do (because the string itself never changes).


> In general, if I use lots of strings -- and my application area os
> computational linguistics -- should I try to use plain String(1..N),
> trying all kinds of tricks to constrain it as above, or
> Ada.Strings.Unbounded are OK, too?

I don't see any reason to use Unbouned_String with the container library, since
it includes indefinite forms allowing you to use type String directly.

It's not really an efficiency issue or anything, just the convenience of being
able to use type String directly without having to go through a secondary type
(Unbouned_String).


> I've tried to leverage plain String, thinking that it being
> unconstrained array can allow for behavior similar to dynamic strings
> in Python, etc.  

Well, that's what Unbounded_String is supposed to do.

If you have a string element, then an indefinite container will do just fine,
since you can always change the element.


> Alas, I cannot append to it doing S := S & Tail;...

No, not with a fixed length string (that's what it means for it to have a
constraint).

However, if this is a container element, then you can always use
Replace_Element to replace the string, e.g.

  M.Replace_Element (C, Element (C) & Tail);

There are other variations: Insert, Include, etc.


> OTOH, I can't index Unbounded string with US(i), -- or can I? -- 

You don't have an index operator, but you do have Element (to return a
character of the string) and Slice (to return a substring).


> and it doesn't look pretty to use Element everywhere...  And if Element, can
> that be well used with prefix notation?

If you're talking about type Unbounded_String, no, you can't use prefix
notation, since that type isn't publicly tagged.



  parent reply	other threads:[~2007-11-26  3:55 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 [this message]
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
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