Skip to main content

eval

Function eval 

Source
pub fn eval(
    expr: &Expr,
    env: &Env,
    heap: Heap,
    fuel: Fuel,
) -> Result<(Value, Heap, Fuel), Error>
Expand description

Evaluate expr against env with the given heap and step budget.

Returns the resulting Value, the updated Heap, and the remaining Fuel. Threading by ownership is intentional: every operation that mutates the heap (alloc, store) produces a new heap that this function returns to its caller.

§Errors

Returns Error::UnboundVariable on free variables, Error::FuelExhausted when the budget is exceeded, Error::DanglingReference on heap accesses to addresses with no live cell, Error::NotAReference on dereference or assignment of a non-ref value, and Error::NotAFunction on application of a non-function value.

§Examples

use lambda_ref_cat::env::Env;
use lambda_ref_cat::eval::{eval, Fuel};
use lambda_ref_cat::heap::Heap;
use lambda_ref_cat::syntax::Expr;

let id = Expr::lam("x", Expr::var("x"));
let (value, _heap, _fuel) = eval(&id, &Env::empty(), Heap::empty(), Fuel::new(100))?;
assert_eq!(format!("{value}"), "\\x. x");