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,f3405cf75879a8dc 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!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: basic questions on using Ada arrays Date: Wed, 06 Oct 2010 20:54:06 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 6 Oct 2010 19:54:06 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="19294"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rmR8c4Bnz4w76GLo1xJCNzhyGrHXQRGU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:kjttUvOyZfunewITC22Tnwnl1nA= sha1:tAoDnA0jZ3SBblfESryZ12iy19Q= Xref: g2news1.google.com comp.lang.ada:14418 Date: 2010-10-06T20:54:06+01:00 List-Id: "Nasser M. Abbasi" writes: > 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? This is probably GNAT-only, and may result in compilation warnings about use of implementation-specific packages, but in recent GNATs there's a package System.Generic_Array_Operations containing generic type X_Scalar is private; type Result_Scalar is private; type X_Vector is array (Integer range <>) of X_Scalar; type Result_Vector is array (Integer range <>) of Result_Scalar; with function Operation (X : X_Scalar) return Result_Scalar; function Vector_Elementwise_Operation (X : X_Vector) return Result_Vector; which you'd instantiate something like type Vector is array (Positive range <>) of Float; function Sin is new System.Generic_Array_Operations.Vector_Elementwise_Operation (X_Scalar => Float, Result_Scalar => Float, X_Vector => Vector, Result_Vector => Vector, Operation => Ada.Numerics.Elementary_Functions.Sin); V : Vector; begin -- Set up V V := Sin (V); (NOT COMPILED!)