3 ms·
> The only real requirement of functional programming is the support of first class functions, the possibility to pass and return functions like any other value
by flowerlad 5y ago
> The only real requirement of functional programming is the support of first class functions, the possibility to pass and return functions like any other values.
By that definition C language supports functional programming. I think a lot of people would disagree with your definition.
- scns 5y agoIt does. I enjoyed the book Functional C by Hartel & Muller a lot: https://www.semanticscholar.org/paper/Functional-C-Hartel-Muller/31acb7abaf3a1962b27be9faa2322038d1ac9ed7 https://www.semanticscholar.org/paper/Functional-C-Hartel-Mu... It uses SML, had fun learning this stuff on the train with termux and vim.
- fstrthnscnd 5y agoActually, first class functions also means the ability to form functions (ie, closures). Javascript for instance has that feature. I think that python also supports it. C OTOH doesn't, but it has other advantages.
- pjmlp 5y agoBasic implementation for car, cdr, map with function pointers and clang blocks, the rest of Lispy stuff is left as an exercise. :) https://godbolt.org/z/Y5qWs4c64 https://godbolt.org/z/Y5qWs4c64
- fstrthnscnd 5y agoThat's cool! C++ had support for partial applications with templates (std::bind iirc), and it was possible to implement closures as objects with the () operator implemented. Now it has support for closure with a dedicated syntax. It would be possible to do something similar in C - a closure is just a function pointer and a bunch of parameters bundled together, but I don't think there's enough flexibility in the language to make it look like regular function calls.