Does Python scoping rule fits the definition of lexical scoping?

前端 未结 4 1328
广开言路
广开言路 2020-12-18 12:05

According to my programming language class, in a language that uses lexical scoping

The body of a function is evaluated in the environment wh

4条回答
  •  猫巷女王i
    2020-12-18 12:33

    Your Python myfun is using the x variable from the environment where it was defined, but that x variable now holds a new value. Lexical scoping means functions remember variables from where they were defined, but it doesn't mean they have to take a snapshot of the values of those variables at the time of function definition.

    Your Standard ML code has two x variables. myfun is using the first variable.

提交回复
热议问题