comp.lang.ada
 help / color / mirror / Atom feed
* Array initialization in SPARK
@ 2010-10-28 10:13 Peter C. Chapin
  2010-10-28 12:47 ` Phil Thornley
  0 siblings, 1 reply; 11+ messages in thread
From: Peter C. Chapin @ 2010-10-28 10:13 UTC (permalink / raw)


Hello!

Consider the following type definition:

type Matrix is array(Natural range <>, Natural range <>) of
Types.Float8;

Now consider the following "obvious" implementation of a matrix
transpose procedure:

   procedure Matrix_Transpose(In_Matrix : in Matrix; Out_Matrix : out
Matrix) is
   begin
      for I in Natural range Out_Matrix'Range(1) loop
         for J in Natural range Out_Matrix'Range(2) loop
            Out_Matrix(I, J) := In_Matrix(J, I);
         end loop;
      end loop;
   end Matrix_Transpose;

This procedure makes assumptions about the relative sizes of the two
matrix objects. I intend to assert those assumptions using
preconditions. However, my question right now is about the
initialization of Out_Matrix. As written the Examiner complains that
the "initial undefined value of Out_Matrix is used in the definition
of Out_Matrix" (or words to that effect). I understand the issue. The
assignment inside the loop only assigns to a single matrix element at
a time. Thus, for example, the first time it executes the resulting
value of Out_Matrix has only one defined element; the rest of the
matrix has its "initial undefined value." I understand that SPARK
works this way because it can't be expected to track individual array
elements because array indexes are dynamic constructs.

In the past when I've had this problem I've just used an aggregate to
initialize the array. In full Ada I can do

   Out_Matrix := (others => (others => 0.0));

However, SPARK isn't happy with this. I'm having trouble figuring out
what would make SPARK happy here. Actually it would be even better if
I could convince the Examiner that the overall effect of the two loops
is to initialize the entire Out_Matrix. I'm not keen about spending
execution time with an aggregate initialization only to overwrite the
initial values anyway. In fact, SPARK complains about doing that sort
of thing with scalar values so it certainly doesn't seem like the
"SPARK way."

Peter



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Array initialization in SPARK
@ 2009-06-15 12:01 xorque
  2009-06-15 12:10 ` xorque
  0 siblings, 1 reply; 11+ messages in thread
From: xorque @ 2009-06-15 12:01 UTC (permalink / raw)


Hello.

What's the correct way to initialize an array in SPARK?

Every method I've tried results in semantic or flow errors:

   9        Status (Index) := 0;
            ^
!!!        Flow Error        : 23: Statement contains reference(s) to
variable
           Status which has an undefined value.

   6      Status : Status_t := (others => 0);
                                ^
***        Syntax Error      : No EXPRESSION can start with reserved
word
           "OTHERS".

   7        (Status_Element_Index_t'First => 0,
                                          ^
***        Syntax Error      : No complete SIMPLE_EXPRESSION can be
followed by
           "=>" here.

And so on...



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

end of thread, other threads:[~2010-10-30 13:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28 10:13 Array initialization in SPARK Peter C. Chapin
2010-10-28 12:47 ` Phil Thornley
2010-10-28 14:51   ` Peter C. Chapin
2010-10-28 15:23     ` Peter C. Chapin
2010-10-28 16:26       ` Alexander Senier
2010-10-28 16:38         ` Phil Thornley
2010-10-30  1:04           ` Phil Clayton
2010-10-30  8:10             ` AdaMagica
2010-10-30 13:11               ` Phil Clayton
  -- strict thread matches above, loose matches on Subject: below --
2009-06-15 12:01 xorque
2009-06-15 12:10 ` xorque

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