Plot Script
|
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 () |
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.
Environment::Environment | ( | ) |
Construct the default environment with built-in procedures and definitions.
void Environment::add_exp | ( | const Atom & | sym, |
const Expression & | exp | ||
) |
Add a mapping from sym argument to the exp argument within the environment.
sym | the symbol to add |
exp | the expression the symbol should map to |
Expression Environment::get_exp | ( | const Atom & | sym | ) | const |
Get the Expression the argument symbol maps to.
sym | the symbol to lookup |
Get the Procedure the argument symbol maps to
sym | the symbol to lookup |
Note: return the default procedure if argument is not a symbol or does not map to a known procedure.
bool Environment::is_exp | ( | const Atom & | sym | ) | const |
Determine if a symbol has been defined as an expression.
sym | the sumbol to lookup |
bool Environment::is_known | ( | const Atom & | sym | ) | const |
Determine if a symbol is known to the environment.
sym | the sumbol to lookup |
bool Environment::is_proc | ( | const Atom & | sym | ) | const |
Determine if a symbol has been defined as a procedure
sym | the symbol to lookup |
void Environment::reset | ( | ) |
Reset the environment to its default state.