pub struct TulispContext { /* private fields */ }Expand description
Represents an instance of the Tulisp interpreter.
Owns the
obarray
which keeps track of all interned Symbols.
All evaluation of Tulisp programs need to be done on a TulispContext
instance.
Implementations§
Source§impl TulispContext
impl TulispContext
Sourcepub fn intern(&mut self, name: &str) -> TulispObject
pub fn intern(&mut self, name: &str) -> TulispObject
Returns an interned symbol with the given name.
Read more about creating and interning symbols here.
pub fn add_special_form(&mut self, name: &str, func: impl TulispFn + Any)
pub fn add_function<Args: 'static, Output: 'static, const NEEDS_CONTEXT: bool, const NUM_ARGS: usize, const NUM_OPTIONAL: usize, const HAS_REST: bool, const HAS_RETURN: bool, const FALLIBLE: bool>( &mut self, name: &str, func: impl TulispCallable<Args, Output, NEEDS_CONTEXT, NUM_ARGS, NUM_OPTIONAL, HAS_REST, HAS_RETURN, FALLIBLE> + 'static, ) -> &mut Self
pub fn add_macro(&mut self, name: &str, func: impl TulispFn)
pub fn set_load_path<P: AsRef<Path>>( &mut self, path: Option<P>, ) -> Result<(), Error>
Sourcepub fn eval(&mut self, value: &TulispObject) -> Result<TulispObject, Error>
pub fn eval(&mut self, value: &TulispObject) -> Result<TulispObject, Error>
Evaluates the given value and returns the result.
Sourcepub fn eval_and_then<T>(
&mut self,
expr: &TulispObject,
f: impl FnOnce(&mut TulispContext, &TulispObject) -> Result<T, Error>,
) -> Result<T, Error>
pub fn eval_and_then<T>( &mut self, expr: &TulispObject, f: impl FnOnce(&mut TulispContext, &TulispObject) -> Result<T, Error>, ) -> Result<T, Error>
Evaluates the given value, run the given function on the result of the evaluation, and returns the result of the function.
Sourcepub fn funcall(
&mut self,
func: &TulispObject,
args: &TulispObject,
) -> Result<TulispObject, Error>
pub fn funcall( &mut self, func: &TulispObject, args: &TulispObject, ) -> Result<TulispObject, Error>
Calls the given function with the given arguments, and returns the result.
Sourcepub fn map(
&mut self,
func: &TulispObject,
seq: &TulispObject,
) -> Result<TulispObject, Error>
pub fn map( &mut self, func: &TulispObject, seq: &TulispObject, ) -> Result<TulispObject, Error>
Maps the given function over the given sequence, and returns the result.
Sourcepub fn filter(
&mut self,
func: &TulispObject,
seq: &TulispObject,
) -> Result<TulispObject, Error>
pub fn filter( &mut self, func: &TulispObject, seq: &TulispObject, ) -> Result<TulispObject, Error>
Filters the given sequence using the given function, and returns the result.
Sourcepub fn reduce(
&mut self,
func: &TulispObject,
seq: &TulispObject,
initial_value: &TulispObject,
) -> Result<TulispObject, Error>
pub fn reduce( &mut self, func: &TulispObject, seq: &TulispObject, initial_value: &TulispObject, ) -> Result<TulispObject, Error>
Reduces the given sequence using the given function, and returns the result.
Sourcepub fn eval_string(&mut self, string: &str) -> Result<TulispObject, Error>
pub fn eval_string(&mut self, string: &str) -> Result<TulispObject, Error>
Parses and evaluates the given string, and returns the result.
Sourcepub fn eval_progn(&mut self, seq: &TulispObject) -> Result<TulispObject, Error>
pub fn eval_progn(&mut self, seq: &TulispObject) -> Result<TulispObject, Error>
Evaluates each item in the given sequence, and returns the value of the last one.
Sourcepub fn eval_each(&mut self, seq: &TulispObject) -> Result<TulispObject, Error>
pub fn eval_each(&mut self, seq: &TulispObject) -> Result<TulispObject, Error>
Evaluates each item in the given sequence, and returns the value of each.