This module provides the Scheme Interpreter, the interactive Shell and
the Scheme Environments.
- exception SchemeException
- This exception is raised
by the Shell and the Interpreter whenever a Scheme expression calls
the built-in (error...) procedure. Its accompanying value is a
tuple containing the arguments to the original error call.
- exception UndefinedException
- This exception is raised by
the Shell and the Interpreter whenever a Scheme command tries to
reference an undefined variable. The referenced name can be obtained
by calling the name method.
- class Environment([parent])
- The base class for
Scheme environments. It provides dictionary access by implementing the
magic __getitem__ and __setitem__ methods. If a
key is not found, it is subsequently looked up in the parent
environment. By default, the parent environment is None
- class Interpreter([environment])
- Instances of this class
represent a Scheme interpreter using the specified environment. If
environment is not specified, it defaults to an instance of
- class SchemeEnvironment5()
- Instances of this class represent a
Scheme Environment as specified by the
(scheme-report-environment 5) call in .
- class Shell()
- Instances of the Shell can be used for
interactive access to the interpreter. When possible, it provides a
readline interface. Each Shell contains its own interpreter.
Each Environment instance represents a single Scheme
environment; its methods can be subdivided into two groups: methods
providing dictionary-like access and methods providing typical
Environments can contain both procedures and variables; the difference
between them is irrelevant to an Environment.
- __setitem__(key, value)
methods allow dictionary access with the subscripting operator
- Returns a list of all variables and procedure
names in this environment.
- Updates the entries in this
Environment with the entries specified in the dictionary
dict. This is especially useful to add multiple user-defined
procedures and variables at once.
- Extends this Environment by returning a new
Environment that has the current Environment as its parent. The
interpreter uses this method to implement local scopes.
Each Interpreter instance represents a single Scheme
interpreter. Different Interpreters do not interfere with each other;
procedures defined in one interpreter will not be visible in other
- Boolean value indicating whether
or not the Interpreter should use tail recursion. By default, it has
the value 1. If set to false, the interpreter will not use tail
recursion. However, by not using tail recursion Scheme expressions
will be subjected to the Python recursion limit.
On the other hand, setting this flag to false will result in slightly
faster execution since Psyche will not have to analyze the parse tree
to mark those expressions in tail context.
- Returns the environment used by the
- Evaluates the string line
and returns the object resulting from evaluating the Scheme expression
specified in line. If the result of this expression is
undefined, eval will return None.
This method will raise all kinds of exceptions if anything went wrong.
- Resets the current environment to the
environment given at initialization by removing all
entries that resulted from evaluating Scheme code. More specifically,
if any standard procedures (such as (map...)) were shadowed as
the result of evaluating a Scheme expression, calling reset
will remove the shadowing definition.
Each Shell instance represents a single interactive
Shell. Different Shells will not interfere with each other.
- complete(text, n)
- Returns the
nth completion of text. Used for tab-completion if the
readline interface is active. The default implementation
completes keywords and elements from the interpreter's environment.
- Executes the read-eval-print loop until
scheme_input returns (quit).
- Prompts on sys.stdout and
reads from sys.stdin until an expression has been read with at
least as many closing brackets as opening brackets. This expression is
then returned as a joined line.