4 ms·
So C has closures now? #include <stdio.h> int x = 1; int f(int y) { return x + y; } int main(argv, argc) { p
by PuercoPop 11y ago
So C has closures now?
#include <stdio.h>
int x = 1;
int f(int y) {
return x + y;
}
int
main(argv, argc) {
printf("f(2): %i\n", f(2));
}
The reason they are called closures is because they close over the, lexical, environment where the function was defined.
Python doesn't have lexical scope, hence it doesn't have closures.
- dalke 11y ago"Python doesn't have lexical scope" Can you explain why https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Closures https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Cl... says: > Python has had support for lexical closures since version 2.2. ... Python's syntax, though, sometimes leads programmers of other languages to think that closures are not supported. Variable scope in Python is implicitly determined by the scope in which one assigns a value to the variable, unless scope is explicitly declared with global or nonlocal. ?