# Crate canrun

Expand description

Canrun is a logic programming library inspired by the *Kanren family of language DSLs.

### Status: Exploratory and Highly Experimental

I’m still quite new to both Rust and logic programming, so there are likely to be rough edges. At best it may be a useful implementation of something that resembles the core concepts of a Kanren while being idiomatically Rusty. At worst it may just be a poor misinterpretation with fatal flaws.

### Quick Start

``````use canrun::{LVar, Query};
use canrun::goals::{both, unify};

let x = LVar::new();
let y = LVar::new();
let goal = both(unify(x, y), unify(1, x));

let result: Vec<_> = goal.query(y).collect();

assert_eq!(result, vec![1])``````

What’s next? Go read a breakdown of this example in the deeper Quick Start explanation.

## Re-exports

`pub use goals::cmp;`
`pub use goals::ops;`
`pub use goals::project;`
`pub use crate::core::*;`
`pub use collections::*;`

## Modules

Unifiable collections with supporting goal functions.
Low level implementation with basic unification, forking and constraint tracking.
Tutorials and other more in-depth documentation (mostly WIP).
Declarative relationships between values.

## Macros

Create a goal that only succeeds if all sub-goals succeed.
Create a goal that yields a state for every successful sub-goal.
Create an `LMap` with automatic key/value `Into<Value<T>>` wrapping.
Create a tuple of logical values with automatic `Into<Value<T>>` wrapping.
Create an `LVec<T>` with automatic `Into<Value<T>>` conversion.

## Structs

A `Goal` that always fails.
A `Goal` that always succeeds.

## Functions

Create a goal that only succeeds if both sub-goals succeed.
Create a goal that gives access to the underlying `State` struct.
Create a goal that succeeds if either sub-goal succeed.
Create a goal that is generated via callback just as it is about to be evaluated.
Create a goal that attempts to unify two values with each other.