|
| |
| Navigation |
Synopsis The runtime representation of Lisp programs and data.
Description There are several aspects of the runtime representation of Lisp programs and Lisp data
that have to be described:
module demo::lang::Lisra::Runtime import Prelude; public data LvalThe data type Lval ( ) takes care of the representation of Lisp values.
It covers integers, atoms, lists and closures (the representation of a functions and
the context in which it will be executed).
A Scope ( ) describes the binding of several related variables to their value.
Since scopes may be nested, an environment (Env) consisted of a list of scope.
The most inner scope is at the start of the list and the most global one at the end.
Creating a new scope is done by makeEnv ( ) which takes a list of variables
(represented by Lvals, in most cases this will be an atom like Atom("X")),
a list of values and creates a new scope in front of the current environment.
The function find ( ) tries to locate the scope in which a name was previously defined.
It searches the nested scopes inside-out and returns the index in the given environment
of the scope in which the name is defined, or -1 if it is not found.
We define ( ) useful constants for true and false (the atoms #t and #f, respectively).
Finally, we define Result ( ) as a tuple of an Lval and an Env.
Each step during interpretation will thus return the value it computed and
a possibly modified environment.
|