Struct tulisp::TulispObject

source ·
pub struct TulispObject { /* private fields */ }
Expand description

A type for representing tulisp objects.

Implementations§

source§

impl TulispObject

source

pub fn nil() -> TulispObject

Create a new nil value.

nil is the False value in Tulisp. It is also the value of an empty list. So it is possible to construct lists, by chaining calls to push on a nil value.

Read more about nil in Emacs Lisp here.

source

pub fn t() -> TulispObject

Create a new t value.

Any value that is not nil is considered True. t may be used as a way to explicitly specify True.

source

pub fn cons(car: TulispObject, cdr: TulispObject) -> TulispObject

Make a cons cell with the given car and cdr values.

source

pub fn equal(&self, other: &TulispObject) -> bool

Returns true if self and other have equal values.

Read more about Emacs equality predicates here.

source

pub fn eq(&self, other: &TulispObject) -> bool

Returns true if self and other are the same object.

Read more about Emacs equality predicates here.

source

pub fn eql(&self, other: &TulispObject) -> bool

Returns true if self and other are the same object, or are indistinguishable numbers.

Read more about Emacs eql here

source

pub fn base_iter(&self) -> BaseIter

Returns an iterator over the values inside self.

source

pub fn iter<T: TryFrom<TulispObject>>(&self) -> Iter<T>

Returns an iterator over the TryInto results on the values inside self.

§Example
let items = ctx.eval_string("'(10 20 30 40 -5)")?;

let items_vec: Vec<i64> = items
    .iter::<i64>()
    .map(|x| x.unwrap()) // works because there are only i64 values.
    .collect();

assert_eq!(items_vec, vec![10, 20, 30, 40, -5]);
source

pub fn push(&self, val: TulispObject) -> Result<&TulispObject, Error>

Adds the given value to the end of a list. Returns an Error if self is not a list.

source

pub fn append(&self, other_list: TulispObject) -> Result<&TulispObject, Error>

Attaches the other list to the end of self. Returns an Error if self is not a list.

source

pub fn fmt_string(&self) -> String

Returns a string representation of self, similar to the Emacs Lisp function princ.

source

pub fn set(&self, to_set: TulispObject) -> Result<(), Error>

Sets a value to self in the current scope. If there was a previous value assigned to self in the current scope, it will be lost.

Returns an Error if self is not a Symbol.

source

pub fn set_scope(&self, to_set: TulispObject) -> Result<(), Error>

Sets a value to self, in the new scope, such that when it is unset, the previous value becomes active again.

Returns an Error if self is not a Symbol.

source

pub fn unset(&self) -> Result<(), Error>

Unsets the value from the most recent scope.

Returns an Error if self is not a Symbol.

source

pub fn get(&self) -> Result<TulispObject, Error>

Gets the value from self.

Returns an Error if self is not a Symbol.

source

pub fn try_float(&self) -> Result<f64, Error>

Returns a float if self holds a float or an int, and an Error otherwise.

source

pub fn try_int(&self) -> Result<i64, Error>

Returns an int if self holds a float or an int, and an Error otherwise.

source

pub fn as_float(&self) -> Result<f64, Error>

Returns a float is self holds a float, and an Error otherwise.

source

pub fn as_int(&self) -> Result<i64, Error>

Returns an int is self holds an int, and an Error otherwise.

source

pub fn as_symbol(&self) -> Result<String, Error>

Returns a string containing symbol name, if self is a symbol, and an Error otherwise.

source

pub fn as_string(&self) -> Result<String, Error>

Returns a string if self contains a string, and an Error otherwise.

source

pub fn as_any(&self) -> Result<Rc<dyn Any>, Error>

Returns a boxed value if self contains a boxed value, and an Error otherwise.

Functions exported to Tulisp can return arbitrary boxed values, which can be extracted with as_any, and downcast to desired types.

§Example
let mut ctx = TulispContext::new();

struct TestStruct {
    value: i64,
}

#[tulisp_fn(add_func = "ctx")]
fn make_any(inp: i64) -> Rc<dyn Any> {
    Rc::new(TestStruct { value: inp })
}

let out = ctx.eval_string("(make_any 25)")?;
let ts = out.as_any()?.downcast::<TestStruct>().unwrap();

assert_eq!(ts.value, 25);
source

pub fn consp(&self) -> bool

Returns True if self is a cons cell.

source

pub fn listp(&self) -> bool

Returns True if self is a list. i.e., a cons cell or nil.

source

pub fn integerp(&self) -> bool

Returns True if self is an integer.

source

pub fn floatp(&self) -> bool

Returns True if self is a float.

source

pub fn numberp(&self) -> bool

Returns True if self is a number. i.e., an integer or a float.

source

pub fn stringp(&self) -> bool

Returns True if self is a string.

source

pub fn symbolp(&self) -> bool

Returns True if self is a Symbol.

source

pub fn boundp(&self) -> bool

Returns True if self is bound in the current scope.

source

pub fn keywordp(&self) -> bool

Returns True if self is a Keyword.

source

pub fn null(&self) -> bool

Returns True if self is nil.

source

pub fn is_truthy(&self) -> bool

Returns True if self is not nil.

source§

impl TulispObject

This impl block contains all the car/cdr/caar/cadr/etc. functions. In addition to the functions documented below, there are also 8 cxxxr functions, like caadr, cdddr, etc., and 16 cxxxxr functions, like caaaar, cddddr, etc., which are not documented here, to avoid repetition.

source

pub fn car(&self) -> Result<TulispObject, Error>

Returns the car of self if it is a list, and an Error otherwise.

source

pub fn cdr(&self) -> Result<TulispObject, Error>

Returns the cdr of self if it is a list, and an Error otherwise.

source

pub fn caar(&self) -> Result<TulispObject, Error>

Returns the car of car of self if it is a list, and an Error otherwise.

source

pub fn cadr(&self) -> Result<TulispObject, Error>

Returns the car of cdr of self if it is a list, and an Error otherwise.

source

pub fn cdar(&self) -> Result<TulispObject, Error>

Returns the cdr of car of self if it is a list, and an Error otherwise.

source

pub fn cddr(&self) -> Result<TulispObject, Error>

Returns the cdr of cdr of self if it is a list, and an Error otherwise.

source

pub fn car_and_then<Out: Default>( &self, f: impl FnOnce(&TulispObject) -> Result<Out, Error> ) -> Result<Out, Error>

Executes the given function on the car of self and returns the result.

source

pub fn cdr_and_then<Out: Default>( &self, f: impl FnOnce(&TulispObject) -> Result<Out, Error> ) -> Result<Out, Error>

Executes the given function on the cdr of self and returns the result.

source

pub fn caar_and_then<Out: Default>( &self, f: impl FnOnce(&TulispObject) -> Result<Out, Error> ) -> Result<Out, Error>

Executes the given function on the car of car of self and returns the result.

source

pub fn cadr_and_then<Out: Default>( &self, f: impl FnOnce(&TulispObject) -> Result<Out, Error> ) -> Result<Out, Error>

Executes the given function on the car of cdr of self and returns the result.

source

pub fn cdar_and_then<Out: Default>( &self, f: impl FnOnce(&TulispObject) -> Result<Out, Error> ) -> Result<Out, Error>

Executes the given function on the cdr of car of self and returns the result.

source

pub fn cddr_and_then<Out: Default>( &self, f: impl FnOnce(&TulispObject) -> Result<Out, Error> ) -> Result<Out, Error>

Executes the given function on the cdr of cdr of self and returns the result.

Trait Implementations§

source§

impl Clone for TulispObject

source§

fn clone(&self) -> TulispObject

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TulispObject

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for TulispObject

source§

fn default() -> Self

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

impl Display for TulispObject

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&str> for TulispObject

source§

fn from(vv: &str) -> Self

Converts to this type from the input type.
source§

impl From<Rc<dyn Any>> for TulispObject

source§

fn from(vv: Rc<dyn Any>) -> Self

Converts to this type from the input type.
source§

impl From<String> for TulispObject

source§

fn from(vv: String) -> Self

Converts to this type from the input type.
source§

impl From<TulispObject> for bool

source§

fn from(value: TulispObject) -> Self

Converts to this type from the input type.
source§

impl From<bool> for TulispObject

source§

fn from(vv: bool) -> Self

Converts to this type from the input type.
source§

impl From<f64> for TulispObject

source§

fn from(vv: f64) -> Self

Converts to this type from the input type.
source§

impl From<i64> for TulispObject

source§

fn from(vv: i64) -> Self

Converts to this type from the input type.
source§

impl FromIterator<TulispObject> for TulispObject

source§

fn from_iter<T: IntoIterator<Item = TulispObject>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl TryFrom<&TulispObject> for f64

§

type Error = Error

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

fn try_from(value: &TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&TulispObject> for i64

§

type Error = Error

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

fn try_from(value: &TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for Option<Rc<dyn Any>>

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for Option<String>

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for Option<f64>

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for Option<i64>

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for Rc<dyn Any>

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for String

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for f64

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TulispObject> for i64

§

type Error = Error

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

fn try_from(value: TulispObject) -> Result<Self, Self::Error>

Performs the conversion.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.