pub struct LogicDb { /* private fields */ }Expand description
An indexed store of logic Clauses queried by goal.
Clauses are kept in assertion order and indexed by predicate symbol and by first ground argument to speed candidate lookup.
Implementations§
Source§impl LogicDb
impl LogicDb
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty clause database.
§Examples
use sim_kernel::{Expr, Symbol};
use sim_lib_logic::LogicDb;
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();
assert!(db.predicate_exists(&Symbol::new("parent")));
assert_eq!(db.clauses().len(), 1);Sourcepub fn predicate_exists(&self, predicate: &Symbol) -> bool
pub fn predicate_exists(&self, predicate: &Symbol) -> bool
Returns whether any clause defines the given predicate symbol.
Sourcepub fn assert_clause_expr(&mut self, expr: Expr) -> Result<ClauseId>
pub fn assert_clause_expr(&mut self, expr: Expr) -> Result<ClauseId>
Parses a clause expression and asserts it, returning its new id.
Sourcepub fn assert_clause(&mut self, clause: Clause) -> Result<ClauseId>
pub fn assert_clause(&mut self, clause: Clause) -> Result<ClauseId>
Adds a parsed clause to the database and updates the indexes.
Sourcepub fn retract_clause_expr(&mut self, expr: &Expr) -> Result<bool>
pub fn retract_clause_expr(&mut self, expr: &Expr) -> Result<bool>
Removes the first clause matching expr, rebuilding the indexes.
Returns whether a matching clause was found and removed.
Sourcepub fn facts(&self, predicate: &Symbol) -> Vec<Expr>
pub fn facts(&self, predicate: &Symbol) -> Vec<Expr>
Returns the surface expressions of every fact for the given predicate.
Sourcepub fn clause_by_id(&self, id: ClauseId) -> Option<&Clause>
pub fn clause_by_id(&self, id: ClauseId) -> Option<&Clause>
Looks up a clause by its identifier.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LogicDb
impl RefUnwindSafe for LogicDb
impl Send for LogicDb
impl Sync for LogicDb
impl Unpin for LogicDb
impl UnsafeUnpin for LogicDb
impl UnwindSafe for LogicDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more