From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4692663255b51613 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!34g2000pru.googlegroups.com!not-for-mail From: Cyrille Newsgroups: comp.lang.ada Subject: Re: on using array index, vectorized operation Date: Sun, 27 Mar 2011 13:01:20 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 83.199.48.181 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1301256081 21287 127.0.0.1 (27 Mar 2011 20:01:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 27 Mar 2011 20:01:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 34g2000pru.googlegroups.com; posting-host=83.199.48.181; posting-account=bNhsVwoAAAB6XmNPWgYcbUm6npIwL2C4 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 ( .NET CLR 3.5.30729),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:19479 Date: 2011-03-27T13:01:20-07:00 List-Id: On Mar 27, 3:31=A0am, "Nasser M. Abbasi" 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) :=3D A(i) =A0 =A0----------- (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 =A0A(1..4) :=3D 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:=3D(2,3,4,5); > A: array(1..5) of integer :=3D (10,20,30,40,50); > > begin > =A0 =A0--A(2..5) :=3D A(1..4); > =A0 =A0--A(i-1) :=3D A(i); =A0--error > > =A0 =A0A(i(1)-1..i(4)-1) :=3D A(i(1)..i(4)); > end t; you can write: A(A'First+1 .. A'Last) :=3D A(A'First .. A'Last-1);