µKanren-rs

github crates.io docs.rs build status

This is a Rust implementation of µKanren, a featherweight relational programming language. See the original Scheme implementation here for reference.

Features

Usage

Here's a simple example, defining and using the appendo predicate.

```rust use ukanren::*;

fn appendo(first: Value, second: Value, out: Value) -> BoxedGoal> { eq(&first, &()) .and(eq(&second, &out)) .or(fresh(move |a: Value, d: Value| { let out = out.clone(); let second = second.clone(); eq(&(a.clone(), d.clone()), &first).and(fresh(move |res: Value| { eq(&(a.clone(), res.clone()), &out).and(appendo(d.clone(), second.clone(), res)) })) })) .boxed() }

let goal = fresh(|x, y| appendo(x, y, [1, 2, 3, 4, 5].tovalue())); asserteq!( goal.run(2).collect::>(), 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.


Made by Eric Zhang for CS 252r. All code is licensed under the MIT License.