Task

Pass a function     as an argument     to another function.



Related task

   First-class functions


 
#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
 