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,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: Mon, 4 Oct 2004 15:21:53 +0200 Message-ID: References: <41547dae$0$91007$39cecf19@news.twtelecom.net> <1g2d9xmnita9f.5ecju0eftkqw$.dlg@40tude.net> <1hl2mizeb27ku$.1f0asrbmb05mi.dlg@40tude.net> <7siml3c62lev$.usczt2y2l19c$.dlg@40tude.net> <15fk5715wm38q.3ie9r3bq8yuz$.dlg@40tude.net> <1ob4dexep087b$.ul8fb1ebgeok.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de tEgnuNoRw2iUXvwdnTPFewozOYXl88uiY716ROC9DBspJFHV0= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:4659 Date: 2004-10-04T15:21:53+02:00 List-Id: On Mon, 04 Oct 2004 12:16:58 GMT, Matthew Heaney wrote: > "Dmitry A. Kazakov" writes: > >> It is because they are not arrays. But why an ordered list should not >> implement an array interface? In my view it should, making the above >> legal for lists. > > Stop obsessing about syntax. Aha, but semantically that all is just a Turing machine. So yes, I am obsessed with syntax. (:-)) > If you want a consistent interface for > containers, you have that in AI-302 (but of course it's not an "array" > interface): > > procedure Op (Container : ) is > C : Cursor := First (Container); > begin > while Has_Element (C) loop > Process (C); --or Process (Element (C)) > Next (C); > end loop; > end Op; > > Actually, if you intend on iterating over all the elements in a > container, the passive iterator is preferred: > > procedure Op (Container : is > begin > Container.Iterate (Process'Access); > end; > > If you have an array type, then you can give it a container-like > interface for the purpose of binding an array object to a generic > algorithm. I showed how to do this in an earlier post. This is what I think the wrong way is - to use Ada's arrays like STL containers, instead of the reverse. You will probably agree that iteration is a fundamental programming pattern. As such, it IMO deserves a separate language construct rather than being hidden in a subroutine call. >> I do! I hate implicit iterators, I prefer loops where >> possible. Especially, because exit conditions, nested iterations, >> exception handling become visible. > > If you intend on traversing every element in the container, then use a > passive iterator. It's more efficient, and less error-prone. > > If you have exit conditions, then go ahead and use an active-iterator > style loop. Just compare: declare C : Cursor := First (Container); begin while Has_Element (C) loop Process (Element (C)); Next (C); end loop; end; with for C in Container'Range loop Process (Container (C)); end loop; You have to know about Cursor, First, Has_Element, Element and Next only to call Process on each element of a container! [ Don't even try to tell me that First is like 'First etc. Because, being obsessed with syntax, I will reply that then it should be named 'First! (:-)) ] >> [ Ranting: 40 years spent in developing readable, safe, well-structured >> language constructs, only to replace them with nested function calls a la >> Lisp? ] > > This is a specious comparison. I tried hard... (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de