Go to the previous, next section.
Environments are first-class objects in MIT Scheme. An environment consists of some bindings and possibly a parent environment, from which other bindings are inherited. The operations in this section reveal the frame-like structure of environments by permitting you to examine the bindings of a particular environment separately from those of its parent.
procedure+: environment? object
Returns #t
if object is an environment; otherwise returns
#f
.
procedure+: environment-has-parent? environment
Returns #t
if environment has a parent environment;
otherwise returns #f
.
procedure+: environment-parent environment
Returns the parent environment of environment. It is an error if environment has no parent.
procedure+: environment-bound-names environment
Returns a newly allocated list of the names (symbols) that are bound by environment. This does not include the names that are bound by the parent environment of environment.
procedure+: environment-bindings environment
Returns a newly allocated list of the bindings of environment;
does not include the bindings of the parent environment.
Each element of this list takes one of two forms: (name)
indicates that name is bound but unassigned, while
(name object)
indicates that name is bound, and
its value is object.
procedure+: environment-bound? environment symbol
Returns #t
if symbol is bound in environment or one
of its ancestor environments; otherwise returns #f
.
procedure+: environment-lookup environment symbol
Symbol must be bound in environment or one of its ancestor environments. Returns the value to which it is bound.
procedure+: environment-assignable? environment symbol
Symbol must be bound in environment or one of its ancestor
environments. Returns #t
if the binding may be modified by side
effect.
procedure+: environment-assign! environment symbol object
Symbol must be bound in environment or one of its ancestor environments, and must be assignable. Modifies the binding to have object as its value, and returns an unspecified result.
procedure+: eval expression environment
Evaluates expression, a list-structure representation (sometimes
called s-expression representation) of a Scheme expression, in
environment. You rarely need eval
in ordinary programs; it
is useful mostly for evaluating expressions that have been created "on
the fly" by a program. eval
is relatively expensive because it
must convert expression to an internal form before it is executed.
(define foo (list '+ 1 2)) (eval foo (the-environment)) => 3
Go to the previous, next section.