From: braver <deliverable@gmail.com>
Subject: Re: OO Style with Ada Containers
Date: Wed, 14 Nov 2007 16:24:25 -0800
Date: 2007-11-14T16:24:25-08:00 [thread overview]
Message-ID: <1195086265.070953.93180@d55g2000hsg.googlegroups.com> (raw)
In-Reply-To: <1195084752.840598.174460@v65g2000hsc.googlegroups.com>
OK, here's how I ended up switching most of my sample application to
object-prefix notation. It gets a Vector of tokens and inserts them
into an Ordered_Map to count word occurrences:
loop
Get_Line(Line, Line_Last);
exit when End_Of_File;
declare
use Ngrams.Token_Vectors;
Tokens : Ngrams.Token_Vector := Ngrams.Split_Vector (Line,
Line_Last);
Token_Cursor : Cursor := Tokens.First;
s : SU.Unbounded_String;
Count : Natural;
begin
while Has_Element(Token_Cursor) loop
s := Element(Token_Cursor);
-- NB is there a Natural'Inc?
Total_Word_Count := Total_Word_Count + 1;
declare
use Word_Counts;
begin
Ngram_Cursor := Ngram_Counts.Find(s);
-- would need to import "=" for private type WC.Cursor:
-- if Ngram_Cursor = WC.No_Element
if not Has_Element(Ngram_Cursor) then
Ngram_Counts.Insert(s, 1);
New_Word_Count := New_Word_Count + 1;
else -- a valid position in Ngram_Pos
Count := Element(Ngram_Cursor);
Ngram_Counts.Replace_Element(Ngram_Cursor, Count+1);
-- or -- but it also replaces the key:
-- WC.Replace(Ngram_Counts, s, Count+1);
end if;
end;
Next(Token_Cursor);
end loop;
end;
end loop;
declare
use Word_Counts;
begin
Ngram_Cursor := Ngram_Counts.First;
while Has_Element(Ngram_Cursor) loop
Put_Line(SU.To_String(Key(Ngram_Cursor)) &
Positive'Image(Element(Ngram_Cursor)));
Next(Ngram_Cursor);
end loop;
end;
As you can see, I've managed to do prefix notation everywhere except
cursors. How do they coexist with prefix notation -- or are they
replaced by something cooler already, too? :)
I'd appreciate any improvements to the above, which I deduced from ARM
and Rosetta Stone examples in an hour and then prefix'ised thanks to
Adam's hint! (Well I've followed Ada since 1987 so the spirit is easy
to follow...)
Cheers,
Alexy
next prev parent reply other threads:[~2007-11-15 0:24 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 [this message]
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
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