Go to the first, previous, next, last section, table of contents.
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.
#t
if object is an environment; otherwise returns
#f
.
#t
if environment has a parent environment;
otherwise returns #f
.
(name)
indicates that name is bound but unassigned, while
(name object)
indicates that name is bound, and
its value is object.
#t
if symbol is bound in environment or one
of its ancestor environments; otherwise returns #f
.
#t
if the binding may be modified by side
effect.
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
The user-initial-environment
is where the top-level
read-eval-print (REP) loop evaluates expressions and stores
definitions. It is a child of the system-global-environment
,
which is where all of the Scheme system definitions are stored. All of
the bindings in system-global-environment
are available when the
current environment is user-initial-environment
. However, any
new bindings that you create in the REP loop (with define
forms or by loading files containing define
forms) occur in
user-initial-environment
.
system-global-environment
is bound to the
environment that's the parent of the user-initial-environment
.
Primitives and system procedures are bound (and sometimes closed) in
this environment.
user-initial-environment
is bound to the default
environment in which typed expressions are evaluated by the top-level
REP loop.
Although all bindings in system-global-environment
are visible to
the REP loop, definitions that are typed at, or loaded by, the
REP loop occur in the user-initial-environment
. This is
partly a safety measure: if you enter a definition that happens to have
the same name as a critical system procedure, your definition will be
visible only to the procedures you define in the
user-initial-environment
; the MIT Scheme system procedures, which
are defined in the system-global-environment
, will continue to
see the original definition.
user-initial-environment
.
The operations in this section return environments that are constructed
by the interpreter. These operations should only be used at the top
level of a file; they are not supported in any other place. In
particular, they force the current environment to be represented in a
form suitable for use by the interpreter. This prevents the compiler
from performing many useful optimizations on such environments, and
forces the use of the interpreter for variable references in them.
However, because all top-level environments (such as
user-initial-environment
) are already interpreter environments,
it does no harm to use such operations on them.
(make-environment expression ...)
is equivalent to:
(let () expression ... (the-environment))
#t
if object is an interpreter environment;
otherwise returns #f
.
Go to the first, previous, next, last section, table of contents.