Domain

Trait Domain 

Source
pub trait Domain:
    Clone
    + Debug
    + PartialEq
    + Eq
    + Hash
    + 'static {
    type Data: Debug + Default;

    // Required methods
    fn val_of_prim_fallback(p: Symbol) -> Option<Val<Self>>;
    fn lookup_fn_ptr(
        p: Symbol,
    ) -> fn(Vec<LazyVal<Self>>, &Evaluator<'_, Self>) -> Result<Val<Self>, String>;
    fn dsl_entry(p: Symbol) -> Option<&'static DSLEntry<Self>>;
    fn dsl_entries() -> Values<'static, Symbol, DSLEntry<Self>>;
    fn type_of_dom_val(&self) -> Type;

    // Provided methods
    fn val_of_prim(p: Symbol) -> Option<Val<Self>> { ... }
    fn type_of_prim(p: Symbol) -> Type { ... }
}
Expand description

The key trait that defines a domain

Required Associated Types§

Source

type Data: Debug + Default

Domain::Data is attached to the Evaluator so all DSL functions will have a mut ref to it (through the handle argument). Feel free to make it the empty tuple if you dont need it. Motivation: For some complicated domains you could leave Ids as pointers and have your domaindata be a system to lookup the actual value from the pointer (and guarantee no value has multiple pointers so that comparison works by Ids). Btw, I briefly implemented it so that the whole system worked by these pointers and it was absolutely miserable, see my notes. But this is here if someone finds a use for it. Ofc be careful not to break function purity with this but otherwise be creative :)

Required Methods§

Source

fn val_of_prim_fallback(p: Symbol) -> Option<Val<Self>>

Source

fn lookup_fn_ptr( p: Symbol, ) -> fn(Vec<LazyVal<Self>>, &Evaluator<'_, Self>) -> Result<Val<Self>, String>

given a function primitive’s symbol return the function pointer you can use to call the function. Breakdown of the function type: it takes a slice of values as input (the args) along with a mut ref to an Expr (I’ll refer to as a “handle”) which is necessary for calling .apply(f,x). This setup with a handle guarantees we can always track when applys happen and log them in our Expr.evals, and also it’s necessary for executing LamClosures in order to look up their body Id (and we wouldn’t want LamClosures to carry around full Exprs because that would break the Expr.evals tracking)

Source

fn dsl_entry(p: Symbol) -> Option<&'static DSLEntry<Self>>

Source

fn dsl_entries() -> Values<'static, Symbol, DSLEntry<Self>>

Source

fn type_of_dom_val(&self) -> Type

Provided Methods§

Source

fn val_of_prim(p: Symbol) -> Option<Val<Self>>

given a primitive’s symbol return a runtime Val object. For function primitives this should return a PrimFun(CurriedFn) object.

Source

fn type_of_prim(p: Symbol) -> Type

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§