What tools are there for functional programming in C?
You can use GCC's nested functions to simulate lambda expressions, in fact, I have a macro to do it for me:
#define lambda(return_type, function_body) \
({ \
return_type anon_func_name_ function_body \
anon_func_name_; \
})
Use like this:
int (*max)(int, int) = lambda (int, (int x, int y) { return x > y ? x : y; });
Functional programming is not about lambdas, it is all about pure functions. So the following broadly promote functional style:
Only use function arguments, do not use global state.
Minimise side effects i.e. printf, or any IO. Return data describing IO which can be executed instead of causing the side effects directly in all functions.
This can be achieved in plain c, no need for magic.