An environment is a separate working space for a program or task. A code module has its own environment: items created inside it stay there unless passed to another module through input or output. section 20.3
Each function call creates a new environment, also called a scope. Its parameters receive the call’s inputs, and variables created during the call belong to that environment. A return value carries a result back to the larger program. section 21.2 section 21.1
A function call’s working space
Calling word_length("Rob", "Banks") gives that call its own word1 and word2 parameters and its local word variable. The function returns the length; its local environment does not become part of the calling code. section 21.2 section 21.1
Figure 21.1. What happens when you make a function call in
? With
and
, the first parameter is mapped in the function’s scope. With
and
, the second parameter is mapped.
is another variable created inside the function.
is the return value. After the function returns, the function scope disappears along with all its variables.
Trace how a function call maps inputs to parameters, creates local variables, returns a value, and then ends its scope. section 21.2







