Home

Awesome

Tiny-Prolog-in-OCaml

A tiny implementation of a small subset of the Prolog language, in OCaml. With small and fun examples.

WARNING: this project only has an educational purpose, for a real-world use of Prolog, please refer to GNU Prolog (gprolog).

This project contains the code and examples for a tiny Prolog implementation, written in the OCaml language.

Example

cat(tom).
mouse(jerry).
fast(X) <-- mouse(X).
stupid(X) <-- cat(X).
$ ./prolog/prolog ./examples/tomandjerry.pl
?- stupid(tom).
  { }
continue ? (o/n) [o] :
$ ./prolog/prolog ./examples/tomandjerry.pl "fast(tom)."
?- fast(tom).
ishuntedby(X, Y) <-- mouse(X), cat(Y).
$ ./prolog/prolog ./examples/tomandjerry.pl "ishuntedby(tom, jerry)."
?- ishuntedby(tom, jerry).
$ ./prolog/prolog ./examples/tomandjerry.pl "ishuntedby(jerry, tom)."
?- ishuntedby(jerry, tom).
  { }
# the mouse always espace the cat!
istrickedby(X, Y) <-- cat(X), mouse(Y).

More example


This software could (soon) run on a... Numworks calculator!

See https://github.com/Naereen/OMicroB/tree/numworks/targets/numworks/tests/prolog for more details.


:scroll: License ? GitHub license

This (small) repository is published under the terms of the MIT license (file LICENSE). © Lilian Besson, 2018.

Maintenance Ask Me Anything ! Analytics

made-with-OCaml made-for-teaching

ForTheBadge built-with-science ForTheBadge uses-badges ForTheBadge uses-git