Function canrun::goals::lazy

source ·
pub fn lazy<F>(fun: F) -> Lazywhere
    F: Fn() -> Box<dyn Goal> + 'static,
Expand description

Create a goal that is generated via callback just as it is about to be evaluated.

The primary uses for this function involve introducing new internal vars. The passed in callback function should return a valid goal to be evaluated.

Examples

use canrun::{lazy, both, unify, LVar, Query};

let x = LVar::new();
let goal = lazy(move || {
    let y = LVar::new();
    Box::new(both(unify(y, 1), unify(x, y)))
});
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![1])