lambda-cat 0.1.0

Untyped lambda calculus interpreter built on comp-cat-rs. Lex, parse, and tree-walk evaluation expressed as Io effects with static dispatch and no panics.
Documentation
//! Runtime values produced by evaluation.
//!
//! In the pure untyped lambda calculus the only runtime value is a closure:
//! a function body paired with the environment that was in scope when the
//! enclosing lambda was evaluated.

use crate::env::Env;
use crate::syntax::{Expr, VarName};

/// A runtime value.
///
/// Spike 1 has a single variant (closures); spike 2 will extend this enum
/// with literals, references, and any other values the GC must trace.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Value {
    /// A function closed over its lexical environment.
    Closure {
        /// The parameter the function binds when applied.
        param: VarName,
        /// The function body.
        body: Expr,
        /// The captured environment at the point of lambda evaluation.
        env: Env,
    },
}

impl Value {
    /// Build a closure value.
    #[must_use]
    pub fn closure(param: VarName, body: Expr, env: Env) -> Self {
        Self::Closure { param, body, env }
    }
}

impl std::fmt::Display for Value {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Closure { param, body, .. } => {
                write!(f, "\\{param}. {body}")
            }
        }
    }
}