pub fn parse_clause_expr(id: ClauseId, expr: Expr) -> Result<Clause>Expand description
Parses a (fact head) or (rule head body) expression into a Clause.
The expression must be a list whose first element is the symbol fact or
rule; any other form is rejected with a logic eval error.
ยงExamples
use sim_kernel::{Expr, Symbol};
use sim_lib_logic::{ClauseId, parse_clause_expr};
let fact = 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")),
]),
]);
let clause = parse_clause_expr(ClauseId(1), fact).unwrap();
assert!(clause.body.is_empty());
assert_eq!(clause.predicate().unwrap(), Symbol::new("parent"));
assert_eq!(clause.arity().unwrap(), 2);