Enum Operator

Source
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

Source

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
Source

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)
Source

pub fn len(&self) -> usize

Counts the number of subgoals in the operator.

§Arguments
  • self
§Return
  • number of subgoals
Source

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§

Source§

impl Clone for Operator

Source§

fn clone(&self) -> Operator

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Operator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Operator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Operator

Source§

fn eq(&self, other: &Operator) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Operator

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.