Higher-order functions: Difference between revisions
Content deleted Content added
Add Julia implementation of Higher-order functions |
No edit summary |
||
Line 1,351: | Line 1,351: | ||
</lang> |
</lang> |
||
=={{header|Order}}== |
|||
Functions in Order can accept any other named function, local variable, or anonymous function as arguments: |
|||
<lang C> |
|||
#include <order/interpreter.h> |
|||
#define ORDER_PP_DEF_8func1 ORDER_PP_FN ( \ |
|||
8fn(8F, \ |
|||
8ap(8F, 8("a string")) )) |
|||
#define ORDER_PP_DEF_8func2 ORDER_PP_FN ( \ |
|||
8fn(8S, \ |
|||
8adjoin(8("func2 called with "), 8S ) )) |
|||
ORDER_PP( |
|||
8func1(8func2) |
|||
) |
|||
// -> "func2 called with ""a string" |
|||
#define ORDER_PP_DEF_8func3 ORDER_PP_FN ( \ |
|||
8fn(8F, \ |
|||
8ap(8F, 1, 2) )) |
|||
ORDER_PP( |
|||
8func3(8plus) |
|||
) |
|||
// -> 3 |
|||
ORDER_PP( |
|||
8ap( 8fn(8X, 8Y, 8mul(8add(8X, 8Y), 8sub(8X, 8Y))), 5, 3) |
|||
) |
|||
// -> 16 |
|||
</lang> |
|||
The only difference between toplevel function definitions, and variables or literals, is that variables and anonymous functions must be called using the <code>8ap</code> syntactic form rather than direct argument application syntax. This is a limitation of the C preprocessor. |
|||
=={{header|OxygenBasic}}== |
=={{header|OxygenBasic}}== |