3 ms·
At the most basic level, though, the comparison remains valid, doesn't it? That is all I'm trying to highlight.
by vickychijwani 15y ago
At the most basic level, though, the comparison remains valid, doesn't it? That is all I'm trying to highlight.
- sp332 15y agoNo. Maybe you're thinking of anonymous functions? A closure binds a function to its scope. https://en.wikipedia.org/wiki/Closure_%28computer_science%29 https://en.wikipedia.org/wiki/Closure_%28computer_science%29
- Arelius 15y agoNo, not really. Closures... close on variables, function pointers, are just pointers to functions. What you are saying is sort of like saying that Classes and Objects are equivalent, creating a closure creates an instance, wheras a function pointer just references the canonical code. Also, don't undervalue anonymous local functions, which is another thing that full closures have over C99 functions.
- msbarnett 15y ago> At the most basic level, though, the comparison remains valid, doesn't it? Given that function pointers can't close over variables in the environment, it's a fairly tenuous comparison. The ability to pass function around is different from the ability of functions to close over their environment. When people talk about closures and their power, they're generally talking about the latter, not the former, at least in my experience.
- mhd 15y agoThe fact that it can be used where other languages would use closures doesn't make them equal, and the language here is pretty definite, you're not using "similar", "like" or "can stand in for"… I can do a tree with an array, that doesn't make them equal. I don't want to sound too harsh, I'm just noting that any blog post that starts out like that is a bit likely to be instantly discarded by some people. And will confuse others later on when they want to learn about closures…