Giter Club home page Giter Club logo

rslogic's Introduction

rslogic Build Status

rslogic is a logic programming framework for Rust inspired by µKanren.

API Documentation

A logical statement is built from variables, states, and goals. Create an initial state, then obtain some variables (and resulting state) from it. Construct a goal consisting of variable bindings, logical operations (AND, OR), or predicates. Then evaluate the goal using the state resulting from making the variables. Evaluating a goal returns all possible solutions to the statement, in the form of a number of states containing variable bindings.

use rslogic::state;
use rslogic::state::{Unif, State, PossibleStates};
use rslogic::goal;
use rslogic::goal::{Goal, fail, unify_val, unify_vars, conj, disj, pred};

let s = state::State::<i32>::empty();
let (v1, s) = s.make_var();
let (v2, s) = s.make_var();

let n = 123;
let g = goal::conj(goal::unify_vars(&v1, &v2), goal::unify_val(&v2, n));

let results = g.eval(&s);
assert_eq!(results.len(), 1);
let bound_value = results[0].get(&v1).unwrap();
assert_eq!(bound_value, &n);

This example creates two variables, v1 and v2, and then assembles a logical expression equivalent to (v1 = v2) && (v2 = 123). When evaluated, the resulting state binds 123 to both v1 and v2.

rslogic's People

Contributors

chalcolith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rslogic's Issues

How to support unification for custom types?

Hello, first of all thanks for taking the time to write this library!

I am interested in implementing unification for lists however I a having trouble understanding how to go about this. More specifically I am baffled by State being parameterized by a single type.
Are we supposed to add a single "Term" type and implement Unif for it?

I think I would like to have something like this:

struct Term {
    Num(i64),
    List(Vec<Box<Term>>)
}

How would I go about implementing the Unif trait for it? I am having trouble forwarding the unification to the i64 implementation since it changes the type of the state return. Am I going about this wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.