Variable Values and Environments

An environment binds variables to ground expressions.

Purpose

To evaluate a Refal Plus construct, it is necessary to know the values of the variables appearing in the construct. The information about the variable values may be represented in a natural way by an environment, which is a function with finite domain that associates each variable from the domain with the variable's value.

Notation

Let Env be an environment with the domain {V1, ..., Vn}, Env(Vj) = Gej being the value the variable Vj is bound to. Then this environment is denoted by {V1 = Ge1, ..., Vn = Gen}. In particular, the empty environment is denoted by {}.

The domain of the environment Env is denoted by dom[Env]. Thus, dom[ {V1 = Ge1, ..., Vn = Gen} ] = {V1, ..., Vn}.

All environments are assumed to satisfy the requirement that a variable's value should be consistent with the type of the variable. Thus, an s-variable's value must be a symbol, a t-variable's value must be a ground term, an e-variable's value must be a ground expression, and a v-variable's value must be a non-empty ground expression.

Env+Env' denotes the environment Env extended with the bindings from the environment Env' in the following way.

dom[Env+Env'] contains the variables from dom[Env'], as well as the variables from dom[Env], whose indices are different from the indices of the variables from dom[Env'].

For all V in dom[Env+Env'], if Env'(V) is defined, then (Env+Env')(V) = Env'(V), otherwise, if Env'(V) is undefined, then (Env+Env')(V) = Env(V).

Examples

{sX = 1, sY = 2} + {sY = 200, sZ = 300}
     = {sX = 1, sY = 200, sZ = 300}

{sX = 1, sY = 2} + {eY = 200, sZ = 300}
     = {sX = 1, eY = 200, sZ = 300}
Related concepts
Variables
Ground Expressions
Restrictions on the Use of Variables