Jump to content

Higher-order functions: Difference between revisions

→‎{{header|D}}: better example I think
(Added Bracmat)
(→‎{{header|D}}: better example I think)
Line 571:
.test(delegate string() { return "literal.D"; }) ;
}</lang>
 
 
There is a simpler version:
 
<lang d>
import std.stdio, std.functional;
 
int someprocedure (int a, int b, int delegate (int, int) f)
{
return f(a, b);
}
 
void main ()
{
writeln("add: ", someprocedure(2, 3, (int a, int b) { return a + b; } ));
writeln("multiply: ", someprocedure(2, 3, (int a, int b) { return a * b; } ));
}
 
</lang>
 
"delegate" keyword is the same as say "function". In "someprocedure" we pass two integers (a and b) and one function f that has two integer inputs and one integer output. We call this procedure with anonymous functions (that return the sum and the times of two integers)
 
=={{header|Delphi}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.