3 ms·
From a functional perspective, this of course doesn't make any sense. But from an imperative perspective it does. A common use for closures in imperative langu
by ceronman 7y ago
From a functional perspective, this of course doesn't make any sense. But from an imperative perspective it does.
A common use for closures in imperative languages is to have custom control structures similar to `if`, `for`, `while`, etc. And in imperative languages mutating values is very important, if you want a new control structure you have to be able to mutate your surrounding variables.
Smalltalk only uses this kind of control structures based on closures. Ruby also uses this a lot, it even changes the meaning of `return` in closures (blocks) to return not from the closure but the enclosing function.