Code Monkey home page Code Monkey logo

proto-vulcan's Introduction

proto-vulcan

CI Status Coverage Status Crates.io version docs.rs docs MIT/APACHE-2.0 Required rustc minimum version

A relational logic programming language embedded in Rust. It started as a yet another miniKanren, but has already evolved into its own language with miniKanren at its core.

In addition to core miniKanren language, proto-vulcan currently provides support for:

  • miniKanren-like breadth-first and Prolog-like depth-first search.
  • Compound types (Example)
  • Disequality constraints CLP(Tree)
  • Finite-domain constraints CLP(FD)
  • Various operators: anyo, conda, condu, onceo, project
  • Pattern matching: match, matche, matcha, matchu
  • Writing goals in Rust embedded inline within proto-vulcan
  • User extension interface

The language is embedded into Rust with macros which parse the language syntax and convert it into Rust. The language looks a lot like Rust, but isn't. For example, fresh variables are presented with Rust closure syntax, and pattern matching looks like Rust match.

Example

extern crate proto_vulcan;
use proto_vulcan::prelude::*;

fn main() {
    let query = proto_vulcan_query!(|q| {
        conde {
            q == 1,
            q == 2,
            q == 3,
        }
    });

    for result in query.run() {
        println!("q = {}", result.q);
    }
}

The example program produces three solutions:

q = 1
q = 2
q = 3

Embedding in Rust

To embed proto-vulcan in Rust, four macros are used: proto_vulcan!, proto_vulcan_closure!, proto_vulcan_query!, and lterm!.

  • proto_vulcan!(<goal>) declares a Proto-vulcan goal, and returns a Rust variable of type Goal.
  • proto_vulcan_closure!(<goal>) declares a Proto-vulcan goal, and returns a Rust variable of type Goal. The goal expression is evaluated lazily when the goal is evaluated. The closure takes ownership of all variables referenced within the closure.
  • proto_vulcan_query!(|a, b, c| { <goal> }) defines a Proto-vulcan query with query-variables a, b and c. The returned value is a Query-struct, that when run, produces an iterator that can be used to iterate over valid solutions to the logic program. The iterator returns a struct with fields named after the query variables.
  • lterm!(<tree-term>) declares a logic tree-term in Rust code, which can be passed to proto-vulcan program within proto_vulcan! or proto_vulcan_query!, or compared with results.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

proto-vulcan's People

Contributors

terohuttunen avatar

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.