Eval

The evaluate function, and Env and Procedure class.

class lispereter.environ.Env(params=(), args=(), outer=None)

An environment: a dict of {‘var’: val} paris, with an outer Env.

Parameters:

params : set, optional

Set of variables.

args : set, optional

The values associated with variables in params.

outer : Env, optional

Outer environment

find(var)

Find the innermost environment where the variable occurs.

Parameters:

var : str

The variable to find.

class lispereter.environ.Procedure(params, body, env)

A user-defined Scheme procedure.

Parameters:

params : set

A set of parameters for the procedure.

body : str

The actual expression of the procedure to execute.

env : Env

The current environment of the procedure.

lispereter.environ.evaluate(x, env=global_env)

Evaluate a given expression x using env.

Parameters:

x : Exp

The expression to evaluate.

env : dict, optional

The environment holding the variables etc.

Returns:

val : (Exp, Atom)

Some answer.

Examples

>>> evaluate(parse("(begin (define r 10) (* pi (* r r)))"))
314.1592653589793
>>> evaluate(parse('(if (< 2 3) (print 2) (print 3))'))
2