Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wartmanm/rust-kanren

A miniKanren implementation in Rust
https://github.com/wartmanm/rust-kanren

Last synced: 3 months ago
JSON representation

A miniKanren implementation in Rust

Awesome Lists containing this project

README

        

# rust-kanren

This is a loose interpretation of miniKanren and cKanren in Rust. It's a work in progress, suggestions are very welcome.

// Display all permutations of the list [1, 2, 3].
// (Using [1,2,3].permutations() would also work, but that's too easy.)

let mut state = State::new();
let result = state.make_var();
let states = state
.and(move |state| length(state, result, 3))
.and(move |state| contains(state, 1, result))
.and(move |state| contains(state, 2, result))
.and(move |state| contains(state, 3, result));

for state in states.flatten() {
let list = state.get_value(result).unwrap();
let items: Vec = list.iter(&state).map(|x| *x.unwrap()).collect();
println!("{:?}", items);
}

// Result:
// [1, 2, 3]
// [1, 3, 2]
// [2, 1, 3]
// [3, 1, 2]
// [2, 3, 1]
// [3, 2, 1]