Rust implementation of µKanren, a featherweight relational programming language.

Overview

µKanren-rs

github crates.io docs.rs build status

This is a Rust implementation of µKanren, a featherweight relational programming language. See the original Scheme implementation here for reference.

Features

  • Structural unification of Scheme-like cons cells.
  • Streams implemented with the Iterator trait.
  • State representation using a persistent vector with triangular substitutions.
  • Conjunction, disjunction, and fresh based on traits (macro-free API).
  • Lazy goal evaluation using inverse-η delay.
  • Integer, bool, char, &str, and unit type atoms.
  • Explicit ToValue trait that converts vectors and arrays into cons-lists.
  • Convenience macro state! to inspect and specify state.

Usage

Here's a simple example, which defines and uses the appendo predicate.

use ukanren::*;

fn appendo(first: Value, second: Value, out: Value) -> BoxedGoal<impl Iterator<Item = State>> {
    eq(&first, &())
        .and(eq(&second, &out))
        .or(fresh(move |a: Value, d: Value, res: Value| {
            eq(&(a.clone(), d.clone()), &first)
                .and(eq(&(a, res.clone()), &out))
                .and(appendo(d, second.clone(), res))
        }))
        .boxed()
}

let iter = run(|x, y| appendo(x, y, [1, 2, 3, 4, 5].to_value()));
assert_eq!(
    iter.collect::<Vec<_>>(),
    vec![
        state![(), [1, 2, 3, 4, 5]],
        state![[1], [2, 3, 4, 5]],
        state![[1, 2], [3, 4, 5]],
        state![[1, 2, 3], [4, 5]],
        state![[1, 2, 3, 4], [5]],
        state![[1, 2, 3, 4, 5], ()],
    ],
);

More examples can be found in the tests/ folder and the API documentation.


Made by Eric Zhang for CS 252r. All code is licensed under the MIT License.
Issues
  • Would love an easier to understand example

    Would love an easier to understand example

    As someone who does not have any familiarity with the concepts put forth in this crate, it would be awesome to have an even simpler example on the front page of the repo because I quite literally have no idea what the current example means. =)

    opened by Pebaz 2
Owner
Eric Zhang
Student at Harvard University and competitive programmer, research in machine learning & programming languages. Previously @jumptrading, @scaleapi, @NVIDIA.
Eric Zhang
A bunch of links to blog posts, articles, videos, etc for learning Rust

rust-learning A bunch of links to blog posts, articles, videos, etc for learning Rust. Feel free to submit a pull request if you have some links/resou

Camille TJHOA 7.1k Sep 15, 2021
Rust explained using easy English

Update 22 December 2020: mdBook can be found here. 28 November 2020: Now also available in simplified Chinese thanks to kumakichi! 1 February 2021: No

null 6.2k Sep 15, 2021
Mote is a systems-programming language designed to be practical, performant, and simple.

Mote NOTE: this following lists the goals for what Mote is supposed to be. It does not promise that any of the features here will be accomplished or a

The Mote Programming Language 14 Jul 28, 2021
Experimental Quantum Computer Simulator + Quantum Chess Implementation

Quantum Chess A somewhat hacky implementation of this paper (made in a week over a holiday). It's not heavily tested and probably has some bugs still

null 18 Feb 10, 2021
An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.

java-2-times-faster-than-c An experiment showing double performance of the code running on JVM comparing to equivalent native C code ⚠️ The title of t

xemantic 48 Aug 15, 2021
a function programming language for real world applications made in rust

a function programming language for real world applications made in rust

Tanay Pingalkar 7 Aug 25, 2021
A peer-reviewed collection of articles/talks/repos which teach concise, idiomatic Rust.

This repository collects resources for writing clean, idiomatic Rust code. Please bring your own. ?? Idiomatic coding means following the conventions

Matthias 2.8k Sep 10, 2021
A programming language somewhat resembling cellular processes.

cytosol An embeddable programming language somewhat resembling cellular processes. State of the implementation tokenising parsing semantic analysis an

null 31 Apr 2, 2021
「Rustでもわかるシステムプログラミング」

learning-systems-programming-in-rust 『Go ならわかるシステムプログラミング』を Rust で書き直すプロジェクト、その名も「Rust ならわかるシステムプログラミング」。 これは何 『Go ならわかるシステムプログラミング』(渋川よしき著)内に書かれている G

Yuki Toyoda 349 Sep 15, 2021
Orion is a lisp dialect.

Orion Orion is a lisp inspired statically typed programming language written in Rust Install From releases Download binary from the releases. With car

Wafelack 202 Aug 21, 2021
A stack based interpreted programming language.

Nightmare Nightmare is a dynamically-typed, procedural programming language that aims to be fast & simple. let user = input() as Int; print("You were

&potato 3 Sep 17, 2021
a cheat-sheet for mathematical notation in Rust 🦀 code form

math-as-rust ?? Based on math-as-code This is a reference to ease developers into mathematical notation by showing comparisons with Rust code.

Eduardo Pereira 9 Sep 12, 2021
Orion lang is a lispy programming language that is strongly and statically typed.

Orion Orion is a lisp inspired statically typed programming language written in Rust Install To install orion you can either: Download binary from the

Wafelack 204 Sep 4, 2021
Simple autoclicker written in Rust, to learn the Rust language.

RClicker is an autoclicker written in Rust, written to learn more about the Rust programming language. RClicker was was written by me to learn more ab

null 6 Jul 12, 2021
Nixt is an interpreted programming language written in Rust

Nixt Nixt is an interpreted lisp inspired programming language written in Rust Index About Examples Installation Build About Nixt goal is to provide a

Wafelack 16 Sep 4, 2021
Raytracer tutorial for PPCA 2021, written in Rust.

Pseudo Photograph Company of ACM 工科和ACM的朋友们都已结课!看看这些了不起的艺术品: 工科 ACM ACM伪摄影公司,简称PPCA,于2021年成立 ?? 这个项目的主要工作是使用Rust语言实现一个光线追踪渲染器。以这个形式,你能通过学习一门新的(而且漂亮的)语

null 98 Sep 2, 2021
Simple daemon built with Rust to track metrics.

Marvin - Metrics Tracker What I cannot create, I do not understand. — Richard Feynman Simple daemon built with Rust to track metrics. The goal is run

João Henrique Machado Silva 3 Aug 30, 2021
An expression based data notation, aimed at transpiling itself to any cascaded data notation.

Lala An expression oriented data notation, aimed at transpiling itself to any cascaded data notation. Lala is separated into three components: Nana, L

null 30 Sep 9, 2021
The Computer Language Benchmarks Game: Rust implementations

The Computer Language Benchmarks Game: Rust implementations This is the version I propose to the The Computer Language Benchmarks Game. For regex-dna,

Guillaume P. 62 Feb 4, 2021