comp.lang.ada
 help / color / mirror / Atom feed
* Multidimensional array vs. array of array
@ 2001-12-11 22:22 Lutz Donnerhacke
  2001-12-11 22:45 ` Mark Lundquist
  2001-12-11 23:03 ` Stephen Leake
  0 siblings, 2 replies; 9+ messages in thread
From: Lutz Donnerhacke @ 2001-12-11 22:22 UTC (permalink / raw)


How does a skilled Ada programmer define a return type containing a
multidimensional array? Of course, the simple solution works:

  type Equations is array (Rows range <>, Columns range <>) of Number;
  type Workspace (row : Rows; col : Columns) is record
    eqs : Equations (Rows'First .. row, Columns'First .. col);
    ... some more stuff ...
  end record;
  function Init_Workspace return Workspace;

But this approach fails miserably on extracting a single row from the result
as well as on construction the result in a recursive function.

I do not found a way to define this type as an array of arrays despite
writing a generic package over the maximum values:
  generic
     type Columns is range <>;
  package
     type Equation  is arry (Columns) of Number;
     type Equations is array (Rows range <>) of Equation;
     type Workspace (row : Rows) is record
        eqs : Equations (Rows'First .. row);
        ... some more stuff ...
     end record;
     function Init_Workspace return Workspace;
  end package;

But this approach does not work for a situation where determining the
resulting constraints is equivalent to simulating the Init_Workspace
recursion. This should be avoided: Error-prone, duplicated and slightly
modified code.

Any idea?



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

end of thread, other threads:[~2001-12-17 15:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-11 22:22 Multidimensional array vs. array of array Lutz Donnerhacke
2001-12-11 22:45 ` Mark Lundquist
2001-12-17 15:56   ` Lutz Donnerhacke
2001-12-11 23:03 ` Stephen Leake
2001-12-12  8:39   ` Lutz Donnerhacke
2001-12-13  0:26     ` James Rogers
2001-12-13  9:02       ` Lutz Donnerhacke
2001-12-13 21:49         ` Nick Roberts
2001-12-14  9:45           ` Lutz Donnerhacke

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