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,dd17afdec1033c93 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder3.cambrium.nl!feeder3.cambrium.nl!feed.tweaknews.nl!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: From Pascal to Ada References: <1193957079.981952.101030@d55g2000hsg.googlegroups.com> Date: Fri, 02 Nov 2007 00:38:34 +0100 Message-ID: <877il1cz9h.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:/h16H3q4Z+7JfOMgGkrgHnvthmg= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tele2 X-Trace: DXC=oc=SC[7jodZoPfY8k93I=V6`Y6aWje^YZhU@_V[o;>BRQe0>=4DdV@P8ES=<`@B?:\e5;lN1=gh8Q Xref: g2news2.google.com comp.lang.ada:2699 Date: 2007-11-02T00:38:34+01:00 List-Id: j.khaldi@oltrelinux.com writes: > Hi, > how do you translate this Pascal code in Ada? > > type > realFunction = function(x: double): double; > > Thanks! In Ada you cannot declare subprogram types, only access-to-subprogram (aka "pointer to subprogram") types. In this case, you would say declare type Real_Function is access function (X : Long_Float) return Long_Float; function F (X : Long_Float) return Long_Float is begin return 42.0 * X; end F; type Vector is array (Positive range <>) of Long_Float; procedure Apply (Func : in Real_Function; To : in out Vector) is begin for J in To'Range loop To (J) := Func (To (J)); -- call the pointed-to function end loop; end Apply; V : Vector (1 .. 100); begin Apply (Func => F'Access, To => V); end; However there are other ways. Ada 2005 introduces anonymous access-to-subprogram types: procedure Apply (Func : access function (X : Long_Float) return Long_Float; To : in out Vector); And it has been possible to use generics since Ada 83: generic with function Func (X : Long_Float) return Long_Float; procedure Apply (To : in out Vector); Why do you ask? -- Ludovic Brenta.