def function_name(formal_parameters): function_body return return_expression``` 1. Create a function with a given signature 2. Set the body of that function to be everything indented after the first line 3. Bind function_name to that function in the current frame
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.