# § Environment Model

This document contains a brief summary about the environment model, which can be used for drawing environment diagrams.

## § Application of a procedure

(procedure arg1 ... argn)

1. Construct a new environment where the formal parameters of the procedure definition are bound to the actual parameters of the procedure application.
2. The parent scope of the environment is the environment were the environment was defined (lexical scoping). NOT the environment where the procedure call is being executed (dynamic scoping).
3. Evaluate the body of the procedure in the context of the new environment.

Evaluating a native procedure does not result in the creation of a new environment, since this is implemented in the Scheme interpreter (i.e., implemented in the host language). However, a higher-order native procedure (e.g., map or apply) can still call non-native procedures and these are consequently evaluated according to the same application rules.

## § Evaluation of a lambda expression

(lambda (par1 ... parn) body)

The resulting procedure object contains…

1. The formal parameter (variable names) of the anonymous procedure.
2. The body of the anonymous procedure.
3. A pointer to the environment in which the procedure was defined.

## § Evaluating define

(define name expression)

Definition of a variable will create a binding in the current environment by associating the symbol with the value obtained by evaluating the expression.

## § Evaluating a set!

(set! variable value)

The evaluation of a set! operation in an environment will result in the first binding that can be found with the given variable name being modified. If no binding exists in a given environment, its lexical environment will be considered. If no binding of that variable name exists, the result is undefined (some Scheme interpreters will raise an error, other will return the new variable).

## § Procedure definition

(define (name par1 ... parn) body)

This case is identical to the evaluation of (define name (lambda (par1 ... parn) body)).