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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a3736685ef876ab2 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!postnews.google.com!d55g2000hsg.googlegroups.com!not-for-mail From: braver Newsgroups: comp.lang.ada Subject: Re: OO Style with Ada Containers Date: Wed, 14 Nov 2007 16:24:25 -0800 Organization: http://groups.google.com Message-ID: <1195086265.070953.93180@d55g2000hsg.googlegroups.com> References: <1195082906.420079.195000@d55g2000hsg.googlegroups.com> <1195084214.480299.13970@t8g2000prg.googlegroups.com> <1195084752.840598.174460@v65g2000hsc.googlegroups.com> NNTP-Posting-Host: 213.145.35.9 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1195086265 20393 127.0.0.1 (15 Nov 2007 00:24:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 Nov 2007 00:24:25 +0000 (UTC) In-Reply-To: <1195084752.840598.174460@v65g2000hsc.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.24 (Macintosh; Intel Mac OS X; U; en),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: d55g2000hsg.googlegroups.com; posting-host=213.145.35.9; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news1.google.com comp.lang.ada:18399 Date: 2007-11-14T16:24:25-08:00 List-Id: 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