Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wartmanm/rust-kanren
A miniKanren implementation in Rust
https://github.com/wartmanm/rust-kanren
Last synced: 1 day ago
JSON representation
A miniKanren implementation in Rust
- Host: GitHub
- URL: https://github.com/wartmanm/rust-kanren
- Owner: wartmanm
- License: lgpl-3.0
- Created: 2015-06-30T01:48:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-08T02:59:26.000Z (over 8 years ago)
- Last Synced: 2024-05-22T22:31:46.428Z (6 months ago)
- Language: Rust
- Size: 104 KB
- Stars: 36
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-formalized-reasoning - rust-kanren - loose interpretation of miniKanren and cKanren. (Kanren / Libraries)
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]