TermUtils

Struct TermUtils 

Source
pub struct TermUtils;
Expand description

Term manipulation utilities

Implementations§

Source§

impl TermUtils

Source

pub fn get_all_variables(term: &Term) -> HashSet<String>

Get all variables in a term (including nested ones)

Collects all unique variable names that appear anywhere in the term. This includes variables nested inside compound terms.

Source

pub fn term_depth(term: &Term) -> usize

Count the depth of nested terms

Returns the maximum nesting depth of a term. Simple terms (atoms, variables, numbers) have depth 1. Compound terms have depth 1 + max depth of arguments.

Source

pub fn term_size(term: &Term) -> usize

Count the total number of subterms

Returns the total size of a term, counting all nodes in the tree. This includes the term itself and all nested subterms.

Source

pub fn contains_variable(term: &Term, var_name: &str) -> bool

Check if a term contains a specific variable

Returns true if the given variable name appears anywhere in the term. This is useful for checking variable dependencies.

Source

pub fn replace_variable(term: &Term, var_name: &str, replacement: &Term) -> Term

Replace all occurrences of a variable with a term

Creates a new term where all instances of the specified variable are replaced with the given replacement term.

Source

pub fn is_ground(term: &Term) -> bool

Check if a term is ground (contains no variables)

A ground term is fully instantiated with no unbound variables. This is important for certain Prolog operations.

Source

pub fn list_to_vec(term: &Term) -> Option<Vec<Term>>

Convert a Prolog list term to a Rust Vec

Prolog lists are represented as nested compound terms with the ‘.’ functor. [1,2,3] is actually .(1, .(2, .(3, []))) This function unpacks that structure into a Rust vector.

Source

pub fn vec_to_list(elements: Vec<Term>) -> Term

Convert a Rust Vec to a Prolog list term

Builds the nested structure that represents a Prolog list. Uses right-to-left folding to build from the tail up.

Source

pub fn fresh_variable( existing_vars: &HashSet<String>, base_name: &str, ) -> String

Generate a fresh variable name not present in the given set

Creates a unique variable name by appending numbers to a base name until a name not in the existing set is found.

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> 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, 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.