Struct Rule

Source
pub struct Rule {
    pub head: Unifiable,
    pub body: Goal,
}
Expand description

Defines a fact or rule.

A rule consists of a head and a body. The head must be a complex term, and the body is a goal.
For facts, the body is set to Nil.

Fields§

§head: Unifiable§body: Goal

Implementations§

Source§

impl Rule

Source

pub fn key(&self) -> String

Creates a key (predicate name) for indexing into the knowledge base.

The name of a predicate consists of its functor and its arity, separated by a slash. For example, for the fact loves(Chandler, Monica), the functor is loves and the arity is 2, therefore the name of the predicate is loves/2.

§Arguments
  • self
§Return
  • key - String
§Usage
use suiron::*;

let query = parse_query("parse($In, $Out, $ErrIn, $ErrOut)");
match query {
    Ok(q) => { println!("{}", q.key()); },
    Err(msg) => { println!("{}", msg); },
}
// Prints: parse/4
Source

pub fn get_head(&self) -> Unifiable

Returns the head of this rule.

§Arguments
  • self
§Return
use suiron::*;

clear_id();
let kb = test_kb();
// Get grandfather rule.
let rule = get_rule(&kb, "grandfather/2", 0);
let head = rule.get_head();
println!("{}", head); // Prints: grandfather($X_1, $Y_2)
Source

pub fn get_body(&self) -> Goal

Returns the body of this rule, which is a goal.

§Arguments
  • self
§Return
§Usage
use suiron::*;

clear_id();
let kb = test_kb();
// Get grandfather rule.
let rule = get_rule(&kb, "grandfather/2", 0);
let body = rule.get_body();
println!("{}", body);  // father($X_1, $Z_3), father($Z_3, $Y_2)
Source

pub fn recreate_variables(self, recreated_vars: &mut VarMap) -> Rule

The scope of a logic variable is the rule or goal in which it is defined.

When the inference algorithm tries to solve a goal, it calls this method to ensure that the variables are unique.

§Argument
  • self
  • recreated_vars - logic variables already recreated
§Return
  • Rule
§Usage
use suiron::*;

clear_id();
match parse_rule("parent($X, $Y) :- mother($X, $Y).") {
    Ok(rule) => {
        let mut var_map = VarMap::new();
        let rule = rule.recreate_variables(&mut var_map);
        println!("{}", rule);
    },
    Err(msg) => { println!("{}", msg); },
}
// Prints: parent($X_1, $Y_2) :- mother($X_1, $Y_2).

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Rule

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 Rule

Source§

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

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

impl Display for Rule

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnwindSafe for Rule

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.