4 ms·
Add is a piece of data, not a function. The equivalent in C would be something like: enum function { add, ... }; // then inside your code switch(
by barrucadu 7y ago
Add is a piece of data, not a function. The equivalent in C would be something like:
enum function { add, ... };
// then inside your code
switch(myfunction) {
case add:
return a + b;
...
Defunctionalisation is about removing higher-order functions, not about naming anonymous functions.
It's not a new trend, the first citation on wikipedia is to a paper in 1972.
- glouwbug 7y agoTwo problems I find: 1. You'll lose function inline optimizations, and also the branch predictor will get thrashed. 2. Local variables in that function essentially become globals.
- mmis1000 7y agoI think it depends on the compiler? In the example of that article, the only place that use the data structure is the when in the function that execute the data structure. A compiler may happily just inline it because no other where use it. And you lost no performance at all. Or it may just decide to generate the result as it and you surely have performance problem now.
- pierrebai 7y agoYou're focusing on my not knowing the syntax and specific of the languages. It's still just giving names to things that did not have a name. Whether the name is a variable name, a function name, a type name, doesn't matter. It's still a fancy, obscure jargonish way of saying "name things".
- dgb23 7y agoThere is naming but that is not the point. The point is that you turn functions into (serializable) data. Nothing fancy happening here.