Plot Script
Classes | Public Member Functions | List of all members
Environment Class Reference

A class representing the interpreter environment. More...

#include <environment.hpp>

Public Member Functions

 Environment ()
 
bool is_known (const Atom &sym) const
 
bool is_exp (const Atom &sym) const
 
Expression get_exp (const Atom &sym) const
 
void add_exp (const Atom &sym, const Expression &exp)
 
bool is_proc (const Atom &sym) const
 
Procedure get_proc (const Atom &sym) const
 
void reset ()
 

Detailed Description

A class representing the interpreter environment.

An instance of Environment allows the interpreter to track previously defined procedures and definitions, either built-in or defined during execution.

To lookup a symbol use one of the member functions is_exp or is_proc, or if you do not care about what the symbol maps to is_known. Depending on the value these member functions return you can obtain the mapped-to value using get_exp or get_proc.

To add an symbol to expression mapping use the add_exp member function.

Constructor & Destructor Documentation

◆ Environment()

Environment::Environment ( )

Construct the default environment with built-in procedures and definitions.

Member Function Documentation

◆ add_exp()

void Environment::add_exp ( const Atom sym,
const Expression exp 
)

Add a mapping from sym argument to the exp argument within the environment.

Parameters
symthe symbol to add
expthe expression the symbol should map to

◆ get_exp()

Expression Environment::get_exp ( const Atom sym) const

Get the Expression the argument symbol maps to.

Parameters
symthe symbol to lookup
Returns
the expression the symbol maps to or an Expression of NoneType

◆ get_proc()

Procedure Environment::get_proc ( const Atom sym) const

Get the Procedure the argument symbol maps to

Parameters
symthe symbol to lookup
Returns
the procedure it maps to

Note: return the default procedure if argument is not a symbol or does not map to a known procedure.

◆ is_exp()

bool Environment::is_exp ( const Atom sym) const

Determine if a symbol has been defined as an expression.

Parameters
symthe sumbol to lookup
Returns
true if the symbol has been defined in the environment as an expression

◆ is_known()

bool Environment::is_known ( const Atom sym) const

Determine if a symbol is known to the environment.

Parameters
symthe sumbol to lookup
Returns
true if the symbol has been defined in the environment

◆ is_proc()

bool Environment::is_proc ( const Atom sym) const

Determine if a symbol has been defined as a procedure

Parameters
symthe symbol to lookup
Returns
true if thr symbol maps to a procedure

◆ reset()

void Environment::reset ( )

Reset the environment to its default state.


The documentation for this class was generated from the following files: