Skip to main content

TulispContext

Struct TulispContext 

Source
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

Source

pub fn new() -> Self

Creates a TulispContext with an empty global scope.

Source

pub fn intern(&mut self, name: &str) -> TulispObject

Returns an interned symbol with the given name.

Read more about creating and interning symbols here.

Source

pub fn add_special_form(&mut self, name: &str, func: impl TulispFn + Any)

Source

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

Source

pub fn add_macro(&mut self, name: &str, func: impl TulispFn)

Source

pub fn set_load_path<P: AsRef<Path>>( &mut self, path: Option<P>, ) -> Result<(), Error>

Source

pub fn eval(&mut self, value: &TulispObject) -> Result<TulispObject, Error>

Evaluates the given value and returns the result.

Source

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.

Source

pub fn funcall( &mut self, func: &TulispObject, args: &TulispObject, ) -> Result<TulispObject, Error>

Calls the given function with the given arguments, and returns the result.

Source

pub fn map( &mut self, func: &TulispObject, seq: &TulispObject, ) -> Result<TulispObject, Error>

Maps the given function over the given sequence, and returns the result.

Source

pub fn filter( &mut self, func: &TulispObject, seq: &TulispObject, ) -> Result<TulispObject, Error>

Filters the given sequence using the given function, and returns the result.

Source

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.

Source

pub fn eval_string(&mut self, string: &str) -> Result<TulispObject, Error>

Parses and evaluates the given string, and returns the result.

Source

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.

Source

pub fn eval_each(&mut self, seq: &TulispObject) -> Result<TulispObject, Error>

Evaluates each item in the given sequence, and returns the value of each.

Source

pub fn eval_file(&mut self, filename: &str) -> Result<TulispObject, Error>

Parses and evaluates the contents of the given file and returns the value.

Trait Implementations§

Source§

impl Default for TulispContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.