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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!news.glorb.com!newscon02.news.prodigy.com!prodigy.net!newsmst01a.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr21.news.prodigy.com.POSTED!4988f22a!not-for-mail From: Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: NNTP-Posting-Host: 64.164.118.168 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr21.news.prodigy.com 1111455798 ST000 64.164.118.168 (Mon, 21 Mar 2005 20:43:18 EST) NNTP-Posting-Date: Mon, 21 Mar 2005 20:43:18 EST Organization: SBC http://yahoo.sbc.com X-UserInfo1: TSU[@I_AOHV[RVT[AROR__TDFZ\@@FXLM@TDOCQDJ@_@FNHBK^RAQFW[ML\THRCKV^GGZKJMGV^^_JSCFFUA_QXFGVSCYRPILH]TRVKC^LSN@DX_HCAFX__@J\DAJBVMY\ZWZCZLPA^MVH_P@\\EOMW\YSXHG__IJQY_@M[A[[AXQ_XDSTAR]\PG]NVAQUVM Date: Tue, 22 Mar 2005 01:43:18 GMT Xref: g2news1.google.com comp.lang.ada:9709 comp.lang.c++:46631 comp.realtime:1578 comp.software-eng:5179 Date: 2005-03-22T01:43:18+00:00 List-Id: "Falk Tannh�user" wrote in message news:d0n0vg$4oa$1@s1.news.oleane.net... > > Perhaps the closest way you can get to this in C++ is > > std::vector Data; > ... > std::for_each(Data.begin(), Data.end(), DoSomething); > > where "DoSomething" evaluates to a so-called "function object" > having an "operator()" accepting a (reference to) "foo_type". > OK. Try this in straight C++. type Index is range -800_000..12_000_000; type Decimal_Fraction is digits 12 range -473.0 .. 2_000.0; type Vector is array (Index range <>) of Decimal_Fraction; V1 : Vector ( -47..600); -- note the negative index range V2 : Vector (-1.. 10); -- also a negative index range V3 : Vector (42..451); -- index starts higher than zero; ............................... function Scan (The_Vector : Vector ; Scan_Value : Decimal_Fraction ) return Natural; -- This function can process any of those vector instances without modification ............................. -- possible implementation of the function function Scan(The_Vector : Vector; Scan_Value : Decimal_Fraction ) return Natrual is Scan_Count : Natural := 0; -- Natual begins at zero begin for I in The_Vector'Range -- No way to index off the end array parameter loop if The_Vector(I) = Scan_Value; -- looking for an exact match Scan_Count := Scan_Count + 1; -- increment the count end if; end loop; return Scan_Count; -- return required; never an implicit return end Scan; ..................................................... I submit this in response to the observation someone made about the alleged added difficulty Ada imposes on the programmer in flexibility of expressiveness. In my own experience, Ada is far more expressive of a larger range of idioms than C++. Note my use of the word "expressive." We can express any idea in any language, but some languages are more expressive of some ideas than others. This is just one example of Ada's flexibility in managing arrays. I could fill many pages with more examples. Of interest, here, is how easy it is to have an array index that begins at a value other than zero, and how easy it is to create a function that will accept any array of any range defined for that index. Yes, I know you can do this in C++, but from my perspective, it is not nearly as easy, expressive, or readable. Counter examples to expressiveness can be illustrated in C++. For example, many programmers prefer the += to the x := x + 1 syntax. This is a minor convenience compared to the final program in Ada. Richard Riehle Disclaimer: I did not compile the code before submitting it so there might be some minor errors. RR