pub enum Operator {
And(Vec<Goal>),
Or(Vec<Goal>),
Time(Vec<Goal>),
Not(Vec<Goal>),
}
Expand description
Defines logical And, Or, etc. An operator holds a vector of goals.
Variants§
And(Vec<Goal>)
Logical And operator.
Or(Vec<Goal>)
Logical Or operator.
Time(Vec<Goal>)
Time - Measures elapsed time.
Not(Vec<Goal>)
Not - Succeeds if goal argument cannot be proven true.
Implementations§
Source§impl Operator
impl Operator
Sourcepub fn split_head_tail(&self) -> (Goal, Operator)
pub fn split_head_tail(&self) -> (Goal, Operator)
Splits the operands into head and tail.
The head is the first Goal. The tail is an Operator (same variant) which holds the remaining Goals.
§Arguments
self
§Return
(head, tail)
- Goal, Operator
§Panics
- If operator is not And or Or.
- If there are no operands.
§Usage
use suiron::*;
let m = parse_subgoal("mother($X, $Y)").unwrap();
let f = parse_subgoal("father($X, $Y)").unwrap();
let s = parse_subgoal("sibling($X, $Y)").unwrap();
let mfs = Operator::Or(vec![m, f, s]); // mother or father or sibling
let (head, tail) = mfs.split_head_tail();
// Head is a Goal: mother
// Tail is an Operator: father or sibling
Sourcepub fn recreate_variables(self, vars: &mut VarMap) -> Operator
pub fn recreate_variables(self, vars: &mut VarMap) -> Operator
Give logic variables unique IDs.
Logic variables in the knowledge base have an ID of 0, but when a rule is fetched from the knowledge base, the logic variables must be given unique IDs.
§Arguments
self
vars
- set of previously recreated variable IDs
§Return
Operator
§Usage
use suiron::*;
// Make an And operator: parent($X, $Y), female($X)
let parent = parse_subgoal("parent($X, $Y)").unwrap();
let female = parse_subgoal("female($X)").unwrap();
let op = and_goal!(parent, female);
let mut var_map = VarMap::new();
let op2 = op.recreate_variables(&mut var_map);
println!("{}", op2); // Prints: parent($X_1, $Y_2), female($X_1)
Sourcepub fn get_subgoal(&self, index: usize) -> Goal
pub fn get_subgoal(&self, index: usize) -> Goal
Get the indexed subgoal from the operator.
The operator must be And or Or.
§Arguments
self
index
§Return
§Usage
use suiron::*;
// Make an And operator: parent($X, $Y), female($X)
let parent = parse_subgoal("parent($X, $Y)").unwrap();
let female = parse_subgoal("female($X)").unwrap();
let op = Operator::And(vec![parent, female]);
let goal = op.get_subgoal(1); // Get second subgoal.
println!("{}", goal); // Prints: female($X)
Trait Implementations§
impl StructuralPartialEq for Operator
Auto Trait Implementations§
impl Freeze for Operator
impl RefUnwindSafe for Operator
impl Send for Operator
impl Sync for Operator
impl Unpin for Operator
impl UnwindSafe for Operator
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