rslogic is a logic programming framework for Rust inspired by µKanren.
A logical statement is built from variables, states, and goals. Create an initial state, then obtain some variables (and resulting state) from it. Construct a goal consisting of variable bindings, logical operations (AND, OR), or predicates. Then evaluate the goal using the state resulting from making the variables. Evaluating a goal returns all possible solutions to the statement, in the form of a number of states containing variable bindings.
``` use rslogic::state; use rslogic::state::{Unif, State, PossibleStates}; use rslogic::goal; use rslogic::goal::{Goal, fail, unifyval, unifyvars, conj, disj, pred};
let s = state::State::
let n = 123; let g = goal::conj(goal::unifyvars(&v1, &v2), goal::unifyval(&v2, n));
let results = g.eval(&s); asserteq!(results.len(), 1); let boundvalue = results[0].get(&v1).unwrap(); asserteq!(boundvalue, &n); ```
This example creates two variables, v1
and v2
, and then assembles a logical expression
equivalent to (v1 = v2) && (v2 = 123)
. When evaluated, the resulting state binds 123
to
both v1
and v2
.