comp.lang.ada
 help / color / mirror / Atom feed
From: j.khaldi@oltrelinux.com
Subject: Re: From Pascal to Ada
Date: Sat, 03 Nov 2007 06:04:46 -0700
Date: 2007-11-03T06:04:46-07:00	[thread overview]
Message-ID: <1194095086.242738.277710@22g2000hsm.googlegroups.com> (raw)
In-Reply-To: <1193960740.756224.6960@y27g2000pre.googlegroups.com>

> 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




  reply	other threads:[~2007-11-03 13:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-01 22:44 From Pascal to Ada j.khaldi
2007-11-01 23:38 ` Ludovic Brenta
2007-11-03 13:29   ` j.khaldi
2007-11-03 13:51     ` Ludovic Brenta
2007-11-01 23:44 ` anon
2007-11-01 23:45 ` Adam Beneschan
2007-11-03 13:04   ` j.khaldi [this message]
2007-11-02  0:01 ` (see below)
2007-11-02  1:02   ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox