<分区> 分区>
According to my programming language class , 在使用词法作用域
的语言中The body of a function is evaluated in the environment where the function is defined, not the environment where the function is called.
例如,SML 遵循以下行为:
val x = 1
fun myfun () =
x
val x = 10
val res = myfun() (* res is 1 since x = 1 when myfun is defined *)
另一方面,Python 不遵循这种行为:
x = 1
def myfun():
return x
x = 10
myfun() # 10 since x = 10 when myfun is called
那为什么is Python described as using lexical scoping ?
