Skip to content

Commit

Permalink
cleanup + update license
Browse files Browse the repository at this point in the history
  • Loading branch information
wartman4404 committed Mar 8, 2016
1 parent 18e8e35 commit 4290400
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 223 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ path = "src/lib.rs"
[profile.release]
debug=true
debug-assertions=false

[dependencies]
ref_slice = "*"
366 changes: 165 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ fn cell_survival(state: State, focus: Var<bool>, sum: Var<i32>, result: Var<bool

fn step(state: State, old: &CellGrid, new: &CellGrid) -> StateIter {
let mut iter = single(state);
for y in (0..old.size.1) {
for x in (0..old.size.0) {
for y in 0..old.size.1 {
for x in 0..old.size.0 {
let neighbors = Box::new(old.neighbors(x, y));
let oldcell = old.get(x, y).unwrap();
let newcell = new.get(x, y).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/nqueens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn main() {
let y = *state.get_value(y).unwrap();

let mut black_square = y % 2 == 0;
for draw_x in (0..n) {
for draw_x in 0..n {
match black_square {
_ if draw_x == x => print!("♕ "),
false => print!(" "),
Expand Down
5 changes: 3 additions & 2 deletions examples/quine.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(ref_slice)]
#[macro_use]
extern crate kanren;
extern crate ref_slice;

use kanren::core::{State, Unifier, Var, ToVar, VarStore};
use kanren::core::{VarWrapper, StateProxy, UnifyResult, UntypedVar};
Expand All @@ -16,6 +16,7 @@ use std::fmt::{self, Write, Debug};
use std::cell::RefCell;
use std::rc::Rc;
use std::io;
use ref_slice::ref_slice;

#[derive(Debug, Copy, Clone)]
enum Tree {
Expand Down Expand Up @@ -241,7 +242,7 @@ impl VarWrapper for Tree {

fn var_iter<'a>(&'a self) -> Option<Box<Iterator<Item=UntypedVar> + 'a>> {
fn slicer<'b, A: Copy>(a: &'b A) -> Option<Box<Iterator<Item=A> + 'b>> {
Some(Box::new(::std::slice::ref_slice(a).iter().map(|x| *x)))
Some(Box::new(ref_slice(a).iter().map(|x| *x)))
}
match *self {
VarSym(ref a) => slicer(a.untyped_ref()),
Expand Down
9 changes: 4 additions & 5 deletions src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ where A: ToVar<VarType=A> + Add<Output=A> + PartialEq, B: ToVar<VarType=A>, C: T
r: C,
result: D,
}
type VarSumConstraint<A> = SumConstraint<A, Var<A>, Var<A>, Var<A>>;
pub type VarSumConstraint<A> = SumConstraint<A, Var<A>, Var<A>, Var<A>>;

impl<A, B, C, D> ToConstraint for SumConstraint<A, B, C, D>
where A: ToVar<VarType=A> + Add<Output=A> + Sub<Output=A> + PartialEq + Clone, B: ToVar<VarType=A>, C: ToVar<VarType=A>, D: ToVar<VarType=A> {
Expand Down Expand Up @@ -108,7 +108,7 @@ where A: ToVar<VarType=Fd>, B: ToVar<VarType=Fd>, C: ToVar<VarType=Fd> {
r: B,
result: C,
}
type VarFdSumConstraint = FdSumConstraint<Var<Fd>, Var<Fd>, Var<Fd>>;
pub type VarFdSumConstraint = FdSumConstraint<Var<Fd>, Var<Fd>, Var<Fd>>;

impl<A, B, C> ToConstraint for FdSumConstraint<A, B, C>
where A: ToVar<VarType=Fd>, B: ToVar<VarType=Fd>, C: ToVar<VarType=Fd> {
Expand Down Expand Up @@ -182,7 +182,7 @@ where A: ToVar<VarType=Fd>, B: ToVar<VarType=Fd> {
l: A,
r: B,
}
type VarFdLessOrEqual = FdLessOrEqual<Var<Fd>, Var<Fd>>;
pub type VarFdLessOrEqual = FdLessOrEqual<Var<Fd>, Var<Fd>>;

impl<A, B> FdLessOrEqual<A, B>
where A: ToVar<VarType=Fd>, B: ToVar<VarType=Fd> {
Expand Down Expand Up @@ -400,7 +400,7 @@ where A: ToVar<VarType=Fd>, B: ToVar<VarType=usize> {
fd: A,
u: B,
}
type VarFdUsizeConstraint = FdUsizeConstraint<Var<Fd>, Var<usize>>;
pub type VarFdUsizeConstraint = FdUsizeConstraint<Var<Fd>, Var<usize>>;

impl<A, B> ToConstraint for FdUsizeConstraint<A, B>
where A: ToVar<VarType=Fd>, B: ToVar<VarType=usize> {
Expand Down Expand Up @@ -535,7 +535,6 @@ fn check_unify(state: &mut StateProxy, list: &mut Cow<Vec<UntypedVar>>, elem: Un

impl<A> Constraint for VarAbsentConstraint<A> where A: ToVar {
fn update(&self, state: &mut StateProxy) -> ConstraintResult<VarAbsentConstraint<A>> {
use core::ConstraintResult::*;
//let mut me = Cow::Borrowed(self);
//push_tail(&mut me, state);

Expand Down
10 changes: 6 additions & 4 deletions src/core/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::{ToVar, StateProxy, VarWrapper, Var, Unifier, VarStore, UnifyResult, U
use std::rc::Rc;
use std::marker::PhantomData;
use list::List;
use ref_slice::ref_slice;

// TODO: Once negative bounds work, add a blanket impl for all but Var and get rid of all of
// this.
Expand Down Expand Up @@ -172,10 +173,11 @@ impl<A, B> VarWrapper for Result<Var<A>, Var<B>> where A: ToVar, B: ToVar {
}).into()
}
fn var_iter<'a>(&'a self) -> Option<Box<Iterator<Item=UntypedVar> + 'a>> {
match self {
&Ok(ref x) => Some(Box::new(::std::slice::ref_slice(x).iter().map(|x| x.untyped()))),
&Err(ref x) => Some(Box::new(::std::slice::ref_slice(x).iter().map(|x| x.untyped()))),
}
let untyped = match *self {
Ok(ref x) => x.untyped_ref(),
Err(ref x) => x.untyped_ref(),
};
Some(Box::new(ref_slice(untyped).iter().cloned()))
}
fn occurs_check(&self, state: &StateProxy, other: UntypedVar) -> bool {
let selfvar = match self {
Expand Down
4 changes: 2 additions & 2 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl Iterator for TailIterIter {

pub type TailIter = Box<TailIterator>;

///! The trait used for the continuation portion of a TailI`terResult` iterator.
trait TailIterator: Any {
///! The trait used for the continuation portion of a `TailIterResult` iterator.
pub trait TailIterator: Any {
fn next(self: Box<Self>) -> TailIterResult;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(get_type_id)]
#![feature(raw)] // used by VarWrapper::get_wrapped_value().
#![feature(drain)] // used by StateProxyMerge (minor optimization)
#![feature(ref_slice)]

extern crate ref_slice;

#[macro_use]
pub mod macros;
Expand Down
5 changes: 2 additions & 3 deletions tests/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extern crate kanren;

extern crate test;
use test::Bencher;
use std::rc::Rc;

use kanren::core::{State, Unifier, Var, ToVar, VarStore};
use kanren::iter::{StateIter, single}; use kanren::core::vars::__;
Expand Down Expand Up @@ -68,7 +67,7 @@ value_wrapper!(Animals);
value_wrapper!(Colors);
value_wrapper!(Drinks);

type VarHouse = (Var<Nationalities>, Var<Rc<Colors>>, Var<Animals>, Var<Drinks>, Var<Cigarettes>);
type VarHouse = (Var<Nationalities>, Var<Colors>, Var<Animals>, Var<Drinks>, Var<Cigarettes>);

#[derive(Default, Debug, Clone, Copy)]
struct House {
Expand All @@ -83,7 +82,7 @@ impl ToVar for House {
type VarType = VarHouse;
fn into_var<U: VarStore+Unifier>(self, state: &mut U) -> Var<VarHouse> {
let nationality = self.nationality.map(|x| state.make_var_of(x)).unwrap_or(state.make_var());
let color = self.color.map(|x| state.make_var_of(Rc::new(x))).unwrap_or(state.make_var());
let color = self.color.map(|x| state.make_var_of(x)).unwrap_or(state.make_var());
let pet = self.pet.map(|x| state.make_var_of(x)).unwrap_or(state.make_var());
let drink = self.drink.map(|x| state.make_var_of(x)).unwrap_or(state.make_var());
let cigarette = self.cigarette.map(|x| state.make_var_of(x)).unwrap_or(state.make_var());
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ fn occurs_check_test() {
if state.ok() {
let mut contents = Vec::new();
let mut node = list1;
for _ in (1..10) {
for _ in 1..10 {
let (h, t) = match state.get_value(node).unwrap() {
&List::Pair(h, t) => (h, t),
_ => panic!(),
Expand Down

0 comments on commit 4290400

Please sign in to comment.