Giter Site home page Giter Site logo

rustpro's Introduction

RustPro

A slow Prolog implementation in Rust

Usage

To start the interpreter you need to run

$ cargo run <file>

where file is a prolog file.

A fact is entered by ending the clause with a dot:

?- lt(zero, succ(zero)).
ok.

A query is specified with a question mark:

?- member(2, cons(1, cons(2, cons(3, nil))))?
yes.

Examples

Zebra puzzle

$ rustpro example/zebra.pro
member(X, cons(X, _)).
member(X, cons(_, Zs)) :- member(X, Zs).
rightOf(X, Y, cons(X, cons(Y, _))).
rightOf(X, Y, cons(_, Zs)) :- rightOf(X, Y, Zs).
nextTo(X, Y, Z) :- rightOf(X, Y, Z).
nextTo(X, Y, Z) :- rightOf(Y, X, Z).
unify(X, X).
zebra(W, Z) :- 
  unify(Hs, cons(house(norwegian, _, _, _, _), cons(_, cons(house(_, _, _, milk, _), cons(_, cons(_, nil)))))),
  member(house(englishman, _, _, _, red), Hs), 
  member(house(spaniard, dog, _, _, _), Hs), 
  member(house(_, _, _, coffee, green), Hs), 
  member(house(ukranian, _, _, tea, _), Hs), 
  rightOf(house(_, _, _, _, green), house(_, _, _, _, ivory), Hs), 
  member(house(_, snails, oldgold, _, _), Hs), 
  member(house(_, _, kools, _, yellow), Hs), 
  nextTo(house(_, _, chesterfields, _, _), house(_, fox, _, _, _), Hs), 
  nextTo(house(_, _, kools, _, _), house(_, horse, _, _, _), Hs), 
  member(house(_, _, lukystrike, juice, _), Hs), 
  member(house(japanese, _, parliament, _, _), Hs), 
  nextTo(house(norwegian, _, _, _, _), house(_, _, _, _, blue), Hs), 
  member(house(Z, zebra, _, _, _), Hs), 
  member(house(W, _, _, water, _), Hs).
?- zebra(W,Z)?
W = norwegian, Z = japanese.
?- 

rustpro's People

Contributors

wert310 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.