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!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: basic questions on using Ada arrays Date: Thu, 7 Oct 2010 19:04:00 -0500 Organization: Jacob Sparre Andersen Message-ID: References: <871v838f5x.fsf@hugsarin.sparre-andersen.dk> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1286496241 24601 69.95.181.76 (8 Oct 2010 00:04:01 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 8 Oct 2010 00:04:01 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 Xref: g2news1.google.com comp.lang.ada:14427 Date: 2010-10-07T19:04:00-05:00 List-Id: "Keith Thompson" wrote in message news:ln8w2apy0u.fsf@nuthaus.mib.org... ... > A more "generic" solution (though it doesn't use generics) is: If you're using an Ada 2005, this solution is better using an anonymous access type, as in that case you can pass any matching subprogram, not just one from the same level. (If you don't do this, this will be annoyingly hard to use.) That is, change as follows: > 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 > type Func_Ptr is access function(F: Float) return Float; Delete this type. > type Float_Array is array(positive range <>) of Float; > > function Apply(Func: Func_Ptr; Arr: Float_Array) return Float_Array is Change this declaration to: function Apply(Func: access function(F: Float) return Float; Arr: Float_Array) return Float_Array is > Result: Float_Array(Arr'Range); > begin > for I in Result'Range loop > Result(I) := Func(Arr(I)); > end loop; > return Result; > end Apply; > > function Init return Float_Array is > nPoints : constant := 100; > del : constant Float := 2.0*Pi/Float(nPoints-1); > Result: Float_Array(1 .. nPoints); > begin > for I in Result'Range loop > Result(I) := Float(I - 1) * del; > end loop; > return result; > end Init; > > X: constant Float_Array := Init; > Y: constant Float_Array := Apply(sin'Access, X); > begin > for I in X'Range loop > Put(X(I), Exp => 0); > Put(" => "); > Put(Y(I), Exp => 0); > New_Line; > end loop; > end Test2; > > [...] Randy.