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!postnews.google.com!22g2000hsm.googlegroups.com!not-for-mail From: j.khaldi@oltrelinux.com Newsgroups: comp.lang.ada Subject: Re: From Pascal to Ada Date: Sat, 03 Nov 2007 06:04:46 -0700 Organization: http://groups.google.com Message-ID: <1194095086.242738.277710@22g2000hsm.googlegroups.com> References: <1193957079.981952.101030@d55g2000hsg.googlegroups.com> <1193960740.756224.6960@y27g2000pre.googlegroups.com> NNTP-Posting-Host: 80.67.112.156 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1194095086 15748 127.0.0.1 (3 Nov 2007 13:04:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 3 Nov 2007 13:04:46 +0000 (UTC) In-Reply-To: <1193960740.756224.6960@y27g2000pre.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 22g2000hsm.googlegroups.com; posting-host=80.67.112.156; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:2706 Date: 2007-11-03T06:04:46-07:00 List-Id: > Ada doesn't really have types that denote *functions*, but instead > they have types that are *access* to function (sort of like a > pointer). Assuming you have a type named Double (in Ada, the standard > floating-point types are named Float and Long_Float): > > type Real_Function is access function (X : Double) return Double; > > (Note: Ada programmers tend not to go for pseudo-Germanic or Hungarian > notation when naming things.) If you have a function like Cos that > takes a Double and returns a Double, you'd say Cos'Access to get a > "pointer" to the function. > > Now, you can not only pass this as a procedure or function parameter, > you can also declare variables of this type and store function > pointers in them. Because of this ability, there are restrictions on > what kinds of functions you can take the 'Access of. Basically, if > Func is nested inside some other procedure Proc, you can't use > Func'Access where a Real_Function is needed, unless the definition of > Real_Function is also nested inside that procedure Proc. (That's an > oversimplification of the rule.) Otherwise you could call Func while > you're not even inside Proc and really screw yourself up. > > But if all you want to do is pass this function to a procedure, you > can use an *anonymous* access type: > > procedure Do_Integrate (Func : access function (X : Double) return > Double); > > and now you can use Do_Integrate(Cos'Access) or whatever other > function you want, even if it's nested. But you can't give a name to > the access-function type in that case. Very clear and interesting. Thank you. Jilani