* Returning a function
@ 2001-06-19 8:56 Hoffmann, Torben
2001-06-19 12:40 ` Marc A. Criley
2001-06-26 2:07 ` Arthur G. Duncan
0 siblings, 2 replies; 3+ messages in thread
From: Hoffmann, Torben @ 2001-06-19 8:56 UTC (permalink / raw)
Hi.
I would like to do some higher-order functions in Ada (just for the fun of
it) - could anyone give me a link which provides information on how to
return a function from a function (or procedure).
Thanks in advance
/Torben
--
NB: This is not an official statement from my employer.
-- Torben Hoffmann
-- Software Engineer iNET: 8 296 5460
-- Intel Denmark Tel: +45 4527 5460
-- Nybrovej 114 Fax: +45 4527 5001
-- DK-2800 Lyngby, Denmark
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Returning a function
2001-06-19 8:56 Returning a function Hoffmann, Torben
@ 2001-06-19 12:40 ` Marc A. Criley
2001-06-26 2:07 ` Arthur G. Duncan
1 sibling, 0 replies; 3+ messages in thread
From: Marc A. Criley @ 2001-06-19 12:40 UTC (permalink / raw)
"Hoffmann, Torben" wrote:
>
> Hi.
>
> I would like to do some higher-order functions in Ada (just for the fun of
> it) - could anyone give me a link which provides information on how to
> return a function from a function (or procedure).
>
> Thanks in advance
> /Torben
Here's a quick example:
procedure FF is
type Operations is (Check_Positive, Check_Even);
type A_Function_Type is access function(X : Integer) return Boolean;
function Is_Positive (A : Integer) return Boolean is
begin
return A > 0;
end Is_Positive;
function Is_Even (Z : Integer) return Boolean is
begin
return (Z mod 2) = 0;
end Is_Even;
function Select_Function(Op : Operations) return A_Function_Type is
begin
if Op = Check_Positive then
return Is_Positive'Access;
elsif Op = Check_Even then
return Is_Even'Access;
end if;
end Select_Function;
AFT : A_Function_Type;
Result : Boolean;
begin
-- Storing the function in a variable, and then
-- invoking it.
AFT := Select_Function(Check_Positive);
Result := AFT.all(-19);
AFT := Select_Function(Check_Even);
Result := AFT.all(-19);
-- Calling it directly via the retrieval function
Result := Select_Function(Check_Positive).all(38);
end FF;
Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Returning a function
2001-06-19 8:56 Returning a function Hoffmann, Torben
2001-06-19 12:40 ` Marc A. Criley
@ 2001-06-26 2:07 ` Arthur G. Duncan
1 sibling, 0 replies; 3+ messages in thread
From: Arthur G. Duncan @ 2001-06-26 2:07 UTC (permalink / raw)
Please excuse the shameless plug, but you might have a look
at my home page:
www.cs.rpi.edu/~duncan
Follow the links in the "tutorials" section, starting with
"Non-Standard Ada Techniques".
Section VI of the tutorial deals with functional programming
in Ada. There is a section on higher-order functions, which
describes a number of functions, such as Map, Reduce, Pointwise,
Pairwise, etc. I also have the Ada source code on line.
Since Ada does not have a "lambda" special form, it is not quite
as easy as in Scheme or in ML.
Hope this helps.
Regards,
- Art Duncan
duncan@cs.rpi.edu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-06-26 2:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-19 8:56 Returning a function Hoffmann, Torben
2001-06-19 12:40 ` Marc A. Criley
2001-06-26 2:07 ` Arthur G. Duncan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox