Tau Prolog is not just an implementation of the logic programming resolution mechanism, but a complete Prolog interpreter. Furthermore, the implementation of this interpreter has been directed by the ISO Prolog Standard.
Tau Prolog is released under the BSD 3-Clause License. This means that anyone is free to use, download, modify and share any version of this project. Tau Prolog has been developed by a team of students from UCLM (University of Castilla-La Mancha, Spain) as an open source project. See Collaborate.
A brief look
Using the Tau Prolog library is simple. Just include a script tag in your html file, like this.
That's it! When the page loads, the
window object is set with a
pl object, which contains the logic related to Prolog.
In order to really use the library, you must create a
Session object, which will contain the methods for parsing programs, looking for answers, etc. This way, we'll use
Session.consult() to read a program,
Session.query() to determine the goal we want to satisfy and
Session.answer() to check if the goal is satisfied within the present database, and what values make it true if there were any variables on the goal. For example:
<script id="likes.pl" type="text/prolog"> likes(sam, salad). likes(dean, pie). likes(sam, apples). likes(dean, whiskey). </script>
var session = pl.create(); session.consult( "likes.pl" );
By calling the
pl.create() method, we create a
Session object, which contais a
consult() method. This method receives the Prolog program. To set the goal we want to check, we need to call the
session.query( "likes(sam, X)." );
Now, when we call the
answer() method on the session variable, the interpreter tries to compute an answer for the goal, looking for facts or rules which unify with the goal. If the search succeeds, a
Substitution object is passed to the callback provided to
answer() as an argument. This
Substitution object contains the variables of the goal and their values. Using a pile of states, the interpreter remembers the last choice point, so it can continue looking for facts from that point in a future search. If there is not any computed answer, the callback invoked on
answer() will return
answer() is called again after having unified the goal previously, the interpreter will continue looking for answers starting from the last choice point.
var callback = console.log; session.answer(callback); // X = salad ; session.answer(callback); // X = apples ; session.answer(callback); // false.
For further information, check the Manual. It contains information about every function in the library, as well as code snippets to try them.
When downloading the library, you can customize the download so you only get the functionality you need. You can download the whole library, or maybe you just the core and the list module, or maybe you already had the library and only need a specific module, etc.
Installation using the npm registry
$ npm install tau-prolog
There is an example on how to use Tau Prolog together with NodeJS in
examples/nodejs. If you have cloned this repository, you can run the example with the following command:
$ npm run example:fruit
The different predicates and modules available in this interpreter are documented on the Documentation section. Even though most of the elements included in this interpreter were implemented following the ISO Prolog Standard, some of them have been modified according to the team judgement. Those differences between the way something was implemented and the ISO Prolog Standard are documented as well.