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,9eef6c480abeecf8,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o13g2000cwo.googlegroups.com!not-for-mail From: brian.b.mcguinness@lmco.com Newsgroups: comp.lang.ada Subject: Dynamic array allocation and STL equivalents? Date: 11 Feb 2005 05:06:56 -0800 Organization: http://groups.google.com Message-ID: <1108127216.221977.60830@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: 192.35.35.36 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1108127220 1807 127.0.0.1 (11 Feb 2005 13:07:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Feb 2005 13:07:00 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=192.35.35.36; posting-account=R0BKUQwAAAAEH1zhMKQoEzkWfZJu3USj Xref: g2news1.google.com comp.lang.ada:8237 Date: 2005-02-11T05:06:56-08:00 List-Id: Back in the mid 1980s, out of curiosity I bought books about a number of programming languages, including LISP and Forth. One of these books was a turquoise and white paperback about Ada by J.G.P. Barnes. During a summer vacation trip, I read the Barnes book while riding for hours down highways in the car. I was impressed with features such as being able to overload operators for newly defined types, the exception handling facilities, and the ability to write constants in a wide variety of bases. My impression was that this was Pascal done right. But at the time I didn't have access to an Ada compiler, so I couldn't play with the language. Recently, while looking through a list of GNU software, I was reminded that there is a Gnu Ada compiler, so I installed it on a computer at home, along with its library. So far I have not found an rpm package of GtkAda for Fedora Core 3, but I am still looking. I would like to write a few Ada programs and play around with the language a bit. From the mid 1980s through the early 1990s I wrote programs in Borland Turbo Pascal 3 through 6, which I was quite fond of, so I shouldn't have much trouble picking up Ada, which has a similar syntax. But there are a few things I don't know how to do. For one thing, I have looked through the Barnes book, the pages of which have turned tan with age, and online, but can't find any information on how to allocate arrays dynamically; there seems to be no equivalent to the C malloc() function or the C++ dimensioned new. If someone would tell me how to do this, I would appreciate it. It would also be useful to know if there is an Ada equivalent of the C++ Standard Template Library, with classes for vectors, associative arrays, and so on. One interesting project would be to create an object class hierarchy to implement APL arrays. In APL, the lengths of an array's dimensions can change, e.g. by concatenating new rows or columns onto a matrix, or concatenating two matrices, and the number of dimensions can also change, e.g. by "laminating" two 12x30 arrays to form a 2x12x30 array. In C++, an obvious solution would be to use STL vectors, e.g.: class RealArray { private: vector dimensions; vector data; public: // define an indexing operator[] to use the dimensions // vector to translate sets of indices into offsets // into the data array ... }; But I don't know how to do this in Ada. I would appreciate suggestions. These might be good topics to cover in a FAQ. --- Brian