Environment Diagrams
visualize the interpreter process
Execution procedure for def statement
Calling user-defined functions
Procedure for calling/applying user-defined functions:
- Add a local frame, forming a new environment
- Bind the function’s formal parameters to its arguments in that frame
- Execute the body of the function in that new environment
Looking up Names in Environments
- Every expression is evaluated in the context of an environment.
- Environments are the memory that keeps track of the correspondence between names and values.
- So far, the current environment is either:
- The global frame alone, or
- A local frame, followed by the global frame.
- Frame is a binding between names and values.
Important:
- An environment is a sequence of frames.
- A name evaluates to the value bound to that name in the earliest frame of the current environment in which that name is found.