This is how to create a "Hello World" kind of program in SWI-Prolog, as installed on Ubuntu (Jaunty).
Prolog usage can be divided into two phases, one in which you write the Prolog program, and the other in which you query the program. The first phase is easiest done in a separate file. So create a file, i.e. test.pl, in you home folder, and edit it with a text editor like GEdit or Kate (Kate is much more powerful).
Then you can load the program from inside prolog after you've started it.
So, let's start the prolog interactive GUI:
Then, in the Prolog GUI, load the file test.pl like so:
Now, if you had some prolog clauses in the test.pl file, you will be able to extract that information by querying.
A very simple test program that you could create is:
/* Some facts about parent relationships */ parent(sam,mark). parent(mark,jim). /* A general rule */ grandparent(Grandparent,Child) :- parent(Grandparent,Parent), parent(Parent,Child).
If you write this in test.pl, and load test.pl according to the instructions above, you'll now be able to query prolog for the grandparent of jim in the following way:
?- grandparent(WHO,jim). WHO = sam ; false.
- "false." here just means that after the first occurence of a matching item, it didn't find anymore items.
- words starting with a Capital letter are treated as variables, while all-lowercase words are treated as atoms.
More explanations about how Prolog works can be found elsewhere. This is just how to get going
When you want to exit the Prolog GUI, type: