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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5d71,304c86061dc69dba X-Google-Attributes: gidf5d71,public X-Google-Thread: 109fba,304c86061dc69dba X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,5cb36983754f64da X-Google-Attributes: gid103376,public X-Google-Thread: 1014db,304c86061dc69dba X-Google-Attributes: gid1014db,public X-Google-ArrivalTime: 2004-02-08 17:26:00 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!news.worldonline.be!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.lang.java Subject: Re: No call for Ada (was Re: Announcing new scripting/prototyping language) Date: 09 Feb 2004 02:24:58 +0100 Organization: Worldonline Belgium Sender: lbrenta@lbrenta Message-ID: References: <20040206174017.7E84F4C4114@lovelace.ada-france.org> <54759e7e.0402071124.322ea376@posting.google.com> <2460735.u7KiuvdgQP@linux1.krischik.com> <54759e7e.0402081525.50c7adae@posting.google.com> NNTP-Posting-Host: ppp-62-235-81-183.tiscali.be Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.worldonline.be 1076289948 22942 62.235.81.183 (9 Feb 2004 01:25:48 GMT) X-Complaints-To: abuse@worldonline.be NNTP-Posting-Date: Mon, 9 Feb 2004 01:25:48 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.ada:5355 comp.lang.c:21271 comp.lang.c++:18201 comp.lang.java:2795 Date: 2004-02-09T02:24:58+01:00 List-Id: msg1825@yahoo.com (MSG) writes: > Martin Krischik wrote: > > > Others did that allready. Besides, you would need an installed Ada compiler > > to verify anyway. > > time apt-get install gnat > => 15 seconds Thanks, I made that package :) > > > > > > Can you do the following in Ada: > > > > > > 1. Write *one* bubble-sort function that will work on different > > > types given an appropriate comparison function > > > > Shure you can. Ada invented templates long bevore C++ was even though of. > > Ada templates are far more powerfull then C++. > > Example? I gave one earlier on c.l.ada. I did not cross-post it to the other newsgroups. Ada templates are superior to C++ templates in several respects. For one thing, you can pass procedures and functions as generic parameters, and the generic formal parameters specify the signature for them. Another thing is that the generic formal parameters can specify several kinds of restrictions to types that are acceptable. > > > 2. If B is a subtype of A, can you pass it to any function that > > > takes A as an argument? (covariance) > > > > subtype as in object orientation: > > > > type Parent is tagged null record; > > type Child is new Parent with null record; > > "null record" ? How about non-null ones? Is a 3D point (x, y, z) a > subtype of a 2D one (x, y) ? type Point_2D is tagged record X, Y : Float; end record; type Point_3D is new Point_2D with record Z : Float; end record; > BTW, does Ada have discriminated unions? (if you don't know what they > are, probably none of the language you used had them) Yes, they are called variant records. > Also, is it possible to corrupt memory in Ada? Yes, if you try hard enough and use Unchecked_Conversion and System.Address instead of the more usual stuff. Very hard in practice. I once tried to do a buffer overflow in Ada, and managed it, but the code to achieve this is rather ugly. Basically, you have to go the extra mile to corrupt memory in Ada. > Is it possible to leak memory in Ada? Yes, just like in C. However, since Ada programmers do much less dynamic memory allocation, this happens much less often than it does in C. Note that there also exists a garbage collector in Ada, as part of AdaCL. > > or subtype as in simple types: > > > > type Day_of_Month is range 1 .. 31; > > subtype Day_of_Febuary is Day_of_Month range 1 .. 29; > > That's neat. If this is neat then dig this: for J in Day_Of_Month loop exit when Month = February and then J >= Day_Of_February'Last; Put_Line (Day_Of_Month'Image (J)); end loop; And think about the implications of these ranges on subprograms that accept only a small set of integer constants as a parameter: type Assessment is (Yes, No, Maybe, Maybe_Not); procedure P (A : Assessment); which is not possible in C: typedef enum { YES, NO, MAYBE, MAYBE_NOT } assessment_t; void P (assessment_t A) { } int main () { P (42); // no compiler check! return 0; } I just tried the above with gcc -Wall and got no warning. This means that only a human carefully reviewing this program will see the mistake (you may also try lint, but this is a tool external to the language and based on heuristics, not language rules). By contrast, the Ada compiler catches the mistake automatically in seconds and leaves you with the confidence that 100% of your code has been screened for such stupid mistakes. -- Ludovic Brenta.