Skip to main content

unify_exprs

Function unify_exprs 

Source
pub fn unify_exprs(
    cx: &mut Cx,
    config: &LogicConfig,
    left: &Expr,
    right: &Expr,
) -> Result<ShapeMatch>
Expand description

Unifies two expressions and reports the result as a kernel ShapeMatch.

On success the returned match is accepting and its captures hold the variable bindings; on a structural mismatch it is a rejecting match. The occurs-check policy comes from config.

ยงExamples

use std::sync::Arc;
use sim_kernel::{Cx, DefaultFactory, EagerPolicy, Expr, Symbol};
use sim_lib_logic::{LogicConfig, unify_exprs};

let mut cx = Cx::new(Arc::new(EagerPolicy), Arc::new(DefaultFactory));
let left = Expr::List(vec![
    Expr::Symbol(Symbol::new("point")),
    Expr::Local(Symbol::new("x")),
]);
let right = Expr::List(vec![
    Expr::Symbol(Symbol::new("point")),
    Expr::Symbol(Symbol::new("origin")),
]);
let matched = unify_exprs(&mut cx, &LogicConfig::default(), &left, &right).unwrap();
assert!(matched.accepted);