Crates.io | ukanren |
lib.rs | ukanren |
version | 0.0.5 |
source | src |
created_at | 2021-09-11 04:49:19.992617 |
updated_at | 2021-09-15 01:45:24.9175 |
description | Rust implementation of µKanren, a featherweight relational programming language. |
homepage | |
repository | https://github.com/ekzhang/ukanren-rs |
max_upload_size | |
id | 449614 |
size | 27,288 |
This is a Rust implementation of µKanren, a featherweight relational programming language. See the original Scheme implementation here for reference.
Iterator
trait.fresh
based on traits (macro-free API).bool
, char
, &str
, and unit type atoms.ToValue
trait that converts vectors and arrays into cons-lists.state!
to inspect and specify state.Here's a simple example, which defines and uses the appendo
predicate.
use ukanren::*;
fn appendo(first: Value, second: Value, out: Value) -> BoxedGoal<impl Iterator<Item = State>> {
eq(&first, &())
.and(eq(&second, &out))
.or(fresh(move |a: Value, d: Value, res: Value| {
eq(&(a.clone(), d.clone()), &first)
.and(eq(&(a, res.clone()), &out))
.and(appendo(d, second.clone(), res))
}))
.boxed()
}
let iter = run(|x, y| appendo(x, y, [1, 2, 3, 4, 5].to_value()));
assert_eq!(
iter.collect::<Vec<_>>(),
vec![
state![(), [1, 2, 3, 4, 5]],
state![[1], [2, 3, 4, 5]],
state![[1, 2], [3, 4, 5]],
state![[1, 2, 3], [4, 5]],
state![[1, 2, 3, 4], [5]],
state![[1, 2, 3, 4, 5], ()],
],
);
More examples can be found in the tests/
folder and the API documentation.