Getting Started: Prolog (SWI-Prolog)

After wrote part I, i forgot that it should be a tutorial for installing and running (or compiling) prolog source code. In advance, we will use SWI-Prolog, a free software of prolog environment licensed under LGPL, which can be downloaded here. The distribution came into binaries and source for multi-environment operating system. It is your choice to use the pre-compiled one instead of building the source code first.

SWI-Prolog is widely use for education, research, also for comercial purposes. It offers some main features, such as:


If SWI-Prolog has been installed into your system and you ran it. You will see interface like this:

Media_httpphotosfakfb_wfbdn

Okay… you just successfully set up your logic programming environtment and ready to be used. Now, we shall move on next step. Running your first program.

So we have this source as our very first prolog source code program. It is based on these knowledges/facts:

man(budianto).
man(denvil).
woman(felicia).
woman(ivon).

By using your favourite text editor you can rewrite the source code above. The next step is save your source code under extension *.pl. Please follow these steps to compile and run your first program:

1. After open SWI-Prolog. Click File > Consult…

Media_httpphotosfakfb_wphhh

The purpose is for linking SWI-Prolog with your pre-written prolog source code.
2. Choose your prolog source code. Please choose the one contains the source above.
Media_httpphotoseakfb_fjmdr

Click Open.
3. As you Open. SWI-Prolog will compile it into its knowledge-based database. Your program is ready to be queried after it has been compiled.
Media_httpphotosbakfb_rwrdl

4. Let’s we try first query to make sure everything is going alright. Yet, we know that felicia is a woman from the facts. We can verify the knowledge in database is valid by querying whether felicia is a woman or not by this syntax.

?- woman(felicia).

as noted in screenshot below

Media_httpphotosaakfb_dzcih

as you can see SWI-Prolog replied yes to the query. It means that it found the knowledge that stated “felicia is a woman” from its knowledge-base database.

Enjoy…

Comments (0)

Leave a comment...