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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4692663255b51613,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: on using array index, vectorized operation Date: Sat, 26 Mar 2011 18:31:26 -0700 Organization: Aioe.org NNTP Server Message-ID: Reply-To: nma@12000.org NNTP-Posting-Host: tUYQ4Ty9mMw9Pdc8TJRFQA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news1.google.com comp.lang.ada:18489 Date: 2011-03-26T18:31:26-07:00 List-Id: 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; --------------------- Now, when I print A, it will show (20,30,40,50,50) as expected. But how can I change the above to do it more directly, as (1)? In Fortran, I can do it as follows: -------------------- program t implicit none integer :: A(1:5)=(/10,20,30,40,50/) integer :: i(1:4)=(/2,3,4,5/) A(i-1) = A(i) end program t --------------------- and in Matlab also ---------------------- EDU>> A=[10 20 30 40 50]; EDU>> i=2:5; EDU>> A(i-1)=A(i) A = 20 30 40 50 50 ------------------------- I am sure it is possible also in Ada to make this operation as short in syntax as it is in the other 2 systems I showed above. I just was not able to figure the syntax yet. thanks --Nasser