codepod icon indicating copy to clipboard operation
codepod copied to clipboard

Scoped variables not working?

Open forrestbao opened this issue 2 years ago • 3 comments

See this repo https://app.codepod.io/repo/57p4jkgi49412wsdr1bt

image

forrestbao avatar Jul 05 '23 08:07 forrestbao

This is the "lexical scoping": descendant scopes can access ancestor scope's variables and functions. Implemented in #284.

lihebi avatar Jul 07 '23 20:07 lihebi

But this isn't always intuitive and convenient. I think we should implement the nonlocal keyword in Python.

lihebi avatar Jul 08 '23 03:07 lihebi

Should the "access" of a child scope be read-only by default? Thus, a scope can access variables in its parent scope but cannot change its value in the parent scope unless declared global or nonlocal?

This is the case for functions. A function definition is not exposed to the parent scope until @export'ed. This well aligns with the tradition in programming.

forrestbao avatar Jul 10 '23 14:07 forrestbao