When we call a function :
- Create a new environment. Its parent pointer points to the current environment.
- In the new environment, we create storage places for each formal parameter.
- Fill in these places with the values of the actual arguments.
- Evaluate the function body in the new environment.
Note! 在UW programming languages课程中,hw5实现了一个scheme-like的 tiny-language,在其中用到了function closure,和这里介绍的方法略有不同。
- map variables to values
- point to the parent environment
Phrasing “return” as an exception allows us to break out of any nested statement evaluation and return to the caller immediately.
提供的jsinterp.py程序中,有一个global_env_update函数,其类似于env_lookup函数,如果 在当前env中找不到vname,则在其parent env中继续找,且若在global_env中还找不到,就会在 global_env中新建variable,这是否不合理