comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic array allocation and STL equivalents?
@ 2005-02-11 13:06 brian.b.mcguinness
  2005-02-11 13:43 ` Jeff C
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: brian.b.mcguinness @ 2005-02-11 13:06 UTC (permalink / raw)


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 <unsigned long> dimensions;
    vector <double>        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




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2005-02-14 15:23 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-11 13:06 Dynamic array allocation and STL equivalents? brian.b.mcguinness
2005-02-11 13:43 ` Jeff C
2005-02-14 15:23   ` Marc A. Criley
2005-02-11 14:41 ` Dmitry A. Kazakov
2005-02-11 15:50   ` Adrien Plisson
2005-02-11 17:47   ` REH
2005-02-12  9:28     ` Dmitry A. Kazakov
2005-02-12 18:52       ` Robert A Duff
2005-02-11 17:24 ` Bobby D. Bryant
2005-02-12  0:06   ` Robert A Duff
2005-02-12  3:45     ` Bobby D. Bryant
2005-02-11 18:07 ` Matthew Heaney
2005-02-11 18:36   ` Martin Krischik
2005-02-11 19:35 ` brian.b.mcguinness
2005-02-12  1:04 ` Jeffrey Carter
2005-02-12  6:19 ` Bobby D. Bryant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox