pub fn query(
cx: &mut Cx,
db: &LogicDb,
config: &LogicConfig,
goal: Expr,
) -> Result<LogicStream>Expand description
Resolves goal against db and returns the answers as a logic stream.
Resolution is bounded by config; the answer count is capped at
config.limits.max_answers.
ยงExamples
use std::sync::Arc;
use sim_kernel::{Cx, DefaultFactory, EagerPolicy, Expr, Symbol};
use sim_lib_logic::{LogicConfig, LogicDb, query};
let mut cx = Cx::new(Arc::new(EagerPolicy), Arc::new(DefaultFactory));
let mut db = LogicDb::new();
db.assert_clause_expr(Expr::List(vec![
Expr::Symbol(Symbol::new("fact")),
Expr::List(vec![
Expr::Symbol(Symbol::new("parent")),
Expr::Symbol(Symbol::new("alice")),
Expr::Symbol(Symbol::new("bob")),
]),
]))
.unwrap();
let goal = Expr::List(vec![
Expr::Symbol(Symbol::new("parent")),
Expr::Symbol(Symbol::new("alice")),
Expr::Local(Symbol::new("who")),
]);
let stream = query(&mut cx, &db, &LogicConfig::default(), goal).unwrap();
let answers = stream.collect(&mut cx, None).unwrap();
assert_eq!(answers.len(), 1);