According to my programming language class, in a language that uses lexical scoping
The body of a function is evaluated in the environment wh
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.