Kajabity Prolog is a lightweight Prolog interpreter written in Java, designed for learning, experimenting, and exploring the foundations of logic programming.
It is open source and available on GitHub (https://github.com/Kajabity/kajabity-prolog) under the Apache License 2.0.
I first wrote it in 2003 as a curiosity project while exploring AI and parsing algorithms, and I’ve recently published it as open source for others to learn from or extend.
It’s a work in progress, and I welcome any comments or contributions.
There’s a lot still to do!
Usage
Kajabity Prolog is a command line Prolog interpreter written in Java (currently v25).
Build it with Maven (see instructions in the README) and run with:
kajabity-prolog
You will be promoted to enter Prolog statements and the answers printed out.
For detailed examples, see the README on GitHub.
Command Line Options
-h, --help
– Print help and exit.-V, --version
– Print version and exit.--init=<inits>
– Specify initialisations file(s).--load=<loads>
– Specify Prolog source file(s) to load.mainFile
– A Prolog source file to load at startup.
Implementation
The Prolog language is based on the unification of logical clauses collected in a database to solve a goal.
The key parts of the application are:
- Database – collects facts and clauses used in Prolog programs.
- Goal – an expression made up of terms to be tested. Variables may be instantiated as goals are solved.
- Solver – applies SLD resolution (Selective Linear Definite clause resolution): chooses the leftmost sub-goal, attempts to unify with a clause head, replaces it with the clause body, and continues recursively with backtracking.
- Unification – finds the Most General Unifier (MGU). Think of it as zipping two sides together, filling missing teeth.
- Tokenising and Parsing – reads Prolog terms into the database or as instructions/goals to solve.
Example:
C:\OSS\Prolog\kajabity-prolog>kajabity-prolog
Running: java --enable-native-access=ALL-UNNAMED -jar "C:\OSS\Prolog\kajabity-prolog\prolog-console\target\prolog-console-0.1.0-SNAPSHOT-shaded.jar"
Kajabity Prolog. Enter "quit." to exit.
>> yes.
Prolog> ?- member(X, [apple, banana, cherry]).
X = apple ;
X = banana ;
X = cherry ;
>> no.
Prolog> quit.
Bye.
Roadmap
- Automated build and deploy pipeline on GitHub.
- Extend command-line interface.
- Documentation and tests.
- Ensure a minimum suite of ISO (or similar) Prolog features are implemented.