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,f3405cf75879a8dc,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!proxad.net!feeder1-2.proxad.net!news.mixmin.net!aioe.org!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: basic questions on using Ada arrays Date: Wed, 06 Oct 2010 08:43:54 -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 X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 Xref: g2news1.google.com comp.lang.ada:14412 Date: 2010-10-06T08:43:54-07:00 List-Id: Ada experts: I am really rusty with Ada. Wanted to find if I apply a function to an array in one call without having to loop calling the function for each entry in the array? Suppose I have an array of values, and I want to take the sin() of each value in the array? This below does not work, last statement is wrong --------------------------------------- with ada.text_io; use ada.text_io; with Ada.Numerics; use Ada.Numerics; with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; with Ada.float_Text_IO; use Ada.float_Text_IO; procedure test2 is nPoints : constant :=100; del : float := 2.0*Pi/float(nPoints-1); x : array(1..nPoints) of float; y : array(1..nPoints) of float; begin x(1):=0.0; for i in 2..nPoints loop x(i) := x(i-1)+del; end loop; x:=sin(x(1..nPoints)); end test2; ------------------------------------ Also, is there a way to initialize an array using a formula or a function call? I know I can do x : array(1..nPoints) of float := (others => 0.0) But I wanted to make each entry in the array to have some value depending on the index value. I did not know how, so that is what the above small loop does, to initialize x array. It would be nice to have been to do this initialization at declaration time. The bigger question really, is if one map functions on array in Ada, or do operations on array in one call, say like multiply a constant by array, without using loops all the time. loops are so out of fashion these days :) Something like this in Fortran ---------------------- program main integer :: x(10)=1 ; x = 5 * x; end program ----------------------- compiles, runs ok, but The Ada code ---------------------- procedure test3 is x : array(1..10) of integer :=(others=>1); begin x:= 5 * x; end test3; --------------- $ gnatmake test3.adb test3.adb:4:12: expected type universal integer test3.adb:4:12: found type of x declared at line 2 I undertand exactly the error and why. My question is how to code it in Ada to the same, without using loops? thanks, --Nasser