Learn Prolog (for Ubuntu users)

Newbie in Prolog? Want to know how to compile programs in this 'Logic based' or 'Rule based' Programming Language?
If yes, then read on..

Assuming you have installed the packages 3 or 1 and 2:
1. gprolog
2. gprolog-doc
3. swi-prolog

where gprolog and swi-prolog are compilers of prolog.

Example to run:
1. Make a file append.pl with your favourite editor say vim or pico.
2. Following are its contents:
%append.pl
append([],Y,Y).
append([A|B],Y,[A|W]) :- append(B, Y,W).
3. Run the following command in the terminal form the directory of your program.
prolog
4. Now run the following command to consult your axioms:
['append.pl'].
5. Following are some queries which I tried:
append(A,B,[1,2]).
A = [],
B = [1,2] ;
A = [1],
B = [2] ;
A = [1,2],
B = [];
false.
6. Remember the following keyword to exit the prolog interface:
halt.

Post comment in case any suggestion or to request to get more information (backtracing using fail. and prunning using cut,! ) on the topic.

No comments:

Post a Comment