Higher-order functions: Difference between revisions
Content added Content deleted
(Added Bracmat) |
(→{{header|D}}: better example I think) |
||
Line 571: | Line 571: | ||
.test(delegate string() { return "literal.D"; }) ; |
.test(delegate string() { return "literal.D"; }) ; |
||
}</lang> |
}</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}}== |
=={{header|Delphi}}== |