comp.lang.ada
 help / color / mirror / Atom feed
From: Phil Clayton <phil.clayton@lineone.net>
Subject: Re: Array initialization in SPARK
Date: Sat, 30 Oct 2010 06:11:41 -0700 (PDT)
Date: 2010-10-30T06:11:41-07:00	[thread overview]
Message-ID: <18dee21a-a23b-4bd7-a85b-ee359811e710@a37g2000yqi.googlegroups.com> (raw)
In-Reply-To: 0570b344-ba2b-4de5-9c5a-a71d61c73bfd@l20g2000yqm.googlegroups.com

On Oct 30, 9:10 am, AdaMagica <christoph.gr...@eurocopter.com> wrote:
> On 30 Okt., 03:04, Phil Clayton <phil.clay...@lineone.net> wrote:
>
> > ...  We
> > could then write something like:
>
> >   Out_Matrix :=
> >      Matrix'(for I in Natural range Out_Matrix'Range(1) =>
> >                (for J in Natural range Out_Matrix'Range(2) =>
> >                   In_Matrix(J, I)));
>
> But we would need an assertion that 'Range(1) equals 'Range(2), else
> we would get Constraint_Error. (Equal lengths would not suffice - no
> sliding there.)

Yes, you would need Out_Matrix'Range(1) = In_Matrix'Range(2) and vice-
versa.
I actually meant to write:

  Out_Matrix :=
     Matrix'(for I in Natural range In_Matrix'Range(2) =>
               (for J in Natural range In_Matrix'Range(1) =>
                  In_Matrix(J, I)));

which still requires the same assertions.  However, this r.h.s. could
be used as the return value of a Matrix_Transpose function which would
enable us to avoid such assertions because we don't have to specify
the unconstrained array size independently, e.g.

  Out_Matrix : Matrix := Matrix_Transpose(In_Matrix);

I suppose this is a more 'functional' style of Ada...

Phil



  reply	other threads:[~2010-10-30 13:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-06-15 12:01 xorque
2009-06-15 12:10 ` xorque
replies disabled

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