- You can download the latest Java Development Kit (JDK) from Oracle. The minimum version required by Projog is Java 8. If using Ubuntu you can instead install Java using the command:
sudo apt-get install openjdk-8-jdk
- After you have installed the JDK, from the command line enter
java -version
to confirm that Java is included in thePATH
operating system environment variable which specifies the set of directories where executable programs are located. - The latest version of Projog can be downloaded from the downloads page.
- Unzip the projog-0.10.0.zip file. This can be done using the command:
jar xvf projog-0.10.0.zip
- From the command line change directory to the newly unzipped directory which will be named
projog-0.10.0
- If using Windows then run the
projog-console.bat
batch script. If using Linux then make the startup script executable using the command:chmod u+x projog-console.sh
and then run it using the command:./projog-console.sh
- From the
?-
prompt you can use Prolog syntax to specify queries e.g.X is 1+1.
and they will be evaluated. - You can enter
quit.
at the?-
prompt to exit the console. - If you provide the names of files, containing Prolog syntax, as arguments to the batch file or shell script e.g.
projog-console.bat towers-of-hanoi-example.pl
then the files will be interpreted automatically when the console starts.
Examples
"Hello world" example.
?- write('hello, world'), nl.
hello, world
yes
Dynamically populate knowledge base with facts.
?- asserta(message(hi, world)).
yes
?- assertz(message(hello, everyone)).
yes
?- asserta(message(hello, world)).
yes
Query using new facts added to the knowledge base.
?- message(hello, everyone).
yes
?- message(hi, everyone).
no
?- message(X, Y).
X = hello
Y = world
yes;
X = hi
Y = world
yes;
X = hello
Y = everyone
yes
?- message(hello, Y).
Y = world
yes;
Y = everyone
yes
Simple example of both unification and arithmetic.
?- W=X, X=1+1, Y is W, Z is -W.
W = 1 + 1
X = 1 + 1
Y = 2
Z = -2
yes
Populate the knowledge base with clauses read from a file containing Prolog syntax.
?- consult('towers-of-hanoi-example.pl').
yes
View the definition of hanoi that has just been parsed from the consulted file.
?- listing(hanoi).
hanoi(N) :- move(N, left, centre, right)
yes
Use the clauses loaded from towers-of-hanoi-example.pl in a query.
?- hanoi(2).
[move,a,disc,from,the,left,pole,to,the,right,pole]
[move,a,disc,from,the,left,pole,to,the,centre,pole]
[move,a,disc,from,the,right,pole,to,the,centre,pole]
yes