- Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.
- First Prolog system was developed in 1972 by Alain Colmerauer and Phillipe Roussel.
- SWI-Prolog is an open source implementation of the programming language Prolog, commonly used for teaching and semantic web applications.
- SWI-Prolog has been under continuous development since 1987. Its main author is Jan Wielemaker. The name SWI is derived from Sociaal-Wetenschappelijke Informatica ("Social Science Informatics"), the former name of the group at the University of Amsterdam, where Wielemaker is employ.
- The first implementations of Prolog were interpreters, however, David H. D. Warren created the Warren Abstract Machine, an early and influential Prolog compiler which came to define the "Edinburgh Prolog" dialect which served as the basis for the syntax of most modern implementations.
How to Install SWI-Prolog on Fedora Core
Login as root (type su, provide password and hit enter).
Apply following commands.
Apply following commands.
# yum -y install pl-devel |
How to Install SWI-Prolog on Ubuntu
Apply this command to install SWI-Prolog on Ubuntu.
# sudo apt-get install gprolog swi-prolog |
Prolog with Netbeans
Prolog can be used with Netbeans IDE. Who are interested navigate to following links.
Working with Prolog
After installing prolog you can provide pl command to run pl interpreter. To exit the interpreter press Ctrl + d. Or type 'halt.'.
To print something like hello world use write command.
To print something like hello world use write command.
?- write('hello world').
hello world
true.
?-
|
To write a prolog program you can use any editor. For example, to create a program called parent.pl you can use the following command(to open a file with gnome editor).
# gedit parent.pl& |
Contents of parent.pl below:
/* upper case used for variables, lower case for constants. Terminate each clause by a period. A clause can be written on multiple lines. Do not leave any blank space. */ /* these are rules */ parent(X,Y):-mother(X,Y). parent(X,Y):-father(X,Y). grandparent(X,Y):-parent(X,Z),parent(Z,Y). /* and these facts */ mother(sonja,mary). mother(sonja,jane). father(john,jim). father(john,bob). father(bob,bill). father(bob,dan). /* and these are goals Find all X that are grandparents of Y. Type ; after the first answer is returned to see more answers. grandparent(X,Y). Find who John is a granparent of grandparent(john,X). */ |
Now run prolog
# pl Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.7.11) Copyright (c) 1990-2009 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). |
Now we will compile the program parent.pl We can use either compile or consult command. Or can simply type ['parent.pl'] to compile the program.
# consult('/path_to_file/file_name') |
Syntax of compile and consult command are same.
Put a period afte every command. Period means end of command.
?- ['parent.pl']. |
Now run queries.
# ?- grandparent(X,Y). |
Acknowledgement and Related Links:
nice post!!
ReplyDeleteThanks for dropping a comment.
ReplyDeletethanks it helped me
ReplyDeleteGlad to know that. Thanks for dropping by..
ReplyDeleteNowhere on SWI Prolog site was the clear, obvious instruction 'yum -y install pl-devel' given! Only circular links and lots of mumbo-jumbo about RPMs. This was so much less painful than what's on there, for someone trying to install Prolog, thank you!
ReplyDeleteHey, thank you. I appreciate that.
ReplyDelete