3 ms·
I think the parent poster was referring to the fact that the critical thing is that a) you can define a function within the scope of another function, and b) yo
by seertaak 9y ago
I think the parent poster was referring to the fact that the critical thing is that a) you can define a function within the scope of another function, and b) you can return the inner function. To do this requires something called a closure, which in general involves some of the local variables being transferred to the heap.
You're right that almost all dynamic languages have this feature, but to give you two notable languages that don't: C doesn't allow defining inner functions. Pascal allows to define inner functions, but doesn't allow you to return them. C++ does allow you to define inner functions (actually functor classes) and allows you to return them, but you need to be explicit about the capturing process.
- btilly 9y agoRight. Anything that you could want to do with an anonymous function, you can. It is less frustrating for me than the fact that the scoping rules for a var in JavaScript mean that you're likely to scope to the nearest function call rather than loop. Despite having anonymous functions, doing what I would want to do with them in JavaScript is often much harder than doing it in Python.