|
|
|
|
|
by adrusi
5101 days ago
|
|
"anonymous function" is a term that refers to a syntax for declaring a function without immediately naming it. A function can't "become" anonymous at runtime by leaving the environment in which it was created. "lexical closure" is a term used to describe the way that functions behave at runtime. A lexical closure can be used as a first class value, and retains the scope that it was created in, as opposed to adopting the scope in which is is called. Example: def foo(bar):
a = 2
bar()
a = 5
def baz():
print a
will print "5" not "2". but note that `baz` is not anonymous because being anonymous is a syntactic quality and in the source code, `baz` is named in the same operation as it is declared. |
|