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:
swiprolog_interface
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...
consult
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.
choosesource
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.
sourcecompile
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
queried

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...

(to be continued)

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...
Code, Prolog

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Leave Comment

(required)

(required)


Spam Protection by WP-SpamFree