From: Cyrille <comar@eu.adacore.com>
Subject: Re: on using array index, vectorized operation
Date: Sun, 27 Mar 2011 13:01:20 -0700 (PDT)
Date: 2011-03-27T13:01:20-07:00 [thread overview]
Message-ID: <dd2a546a-50d8-4dc4-8455-a50aa1454f1b@34g2000pru.googlegroups.com> (raw)
In-Reply-To: imm41o$v0g$1@speranza.aioe.org
On Mar 27, 3:31 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> Hello;
>
> Many times I need to operate on an array using an index
> by doing some operation on the index itself as a variable
> (such as shifting for example).
>
> This below is a very simple example of what I mean.
>
> Given an array A, I might want to do
>
> A(i-1) := A(i) ----------- (1)
>
> where 'i' above is a variable which contain in it some index
> locations to use to index into the array A.
>
> In Ada, I can do the above, but I am a little clumsy in doing
> it. I know I can use array slicing as in A(1..4) := A(2..5),
> but wanted to do it when the index itself is a variable, as in (1)
> above. Since in other cases, I have to do more operations on the index
> itself, and so it needs to be in a variable.
>
> This is what I tried so far, and my goal to see if I can
> shorten this more:
>
> ------------------------
> procedure t is
> i: constant array (1..4) of integer:=(2,3,4,5);
> A: array(1..5) of integer := (10,20,30,40,50);
>
> begin
> --A(2..5) := A(1..4);
> --A(i-1) := A(i); --error
>
> A(i(1)-1..i(4)-1) := A(i(1)..i(4));
> end t;
you can write:
A(A'First+1 .. A'Last) := A(A'First .. A'Last-1);
next prev parent reply other threads:[~2011-03-27 20:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-27 1:31 on using array index, vectorized operation Nasser M. Abbasi
2011-03-27 18:48 ` Nasser M. Abbasi
2011-03-27 20:01 ` Cyrille [this message]
2011-03-27 20:44 ` Nasser M. Abbasi
2011-03-27 21:02 ` Pascal Obry
2011-03-27 21:30 ` Shark8
2011-03-27 22:00 ` Nasser M. Abbasi
2011-03-27 22:37 ` Phil Clayton
2011-03-27 22:43 ` Nasser M. Abbasi
2011-03-27 22:59 ` Phil Clayton
2011-03-27 22:09 ` Phil Clayton
2011-03-27 22:12 ` Nasser M. Abbasi
2011-03-27 22:23 ` Nasser M. Abbasi
2011-03-29 2:50 ` Randy Brukardt
2011-03-29 4:55 ` Nasser M. Abbasi
2011-03-29 20:11 ` Phil Clayton
2011-03-29 21:17 ` Nasser M. Abbasi
2011-03-29 22:49 ` Phil Clayton
2011-03-29 23:47 ` Nasser M. Abbasi
2011-03-30 13:00 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox