SWI Prolog

Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics. Prolog has its roots in formal logic, and unlike many other programming languages, Prolog is declarative: The program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations. The language was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s and the first Prolog system was developed in 1972 by Colmerauer with Philippe Roussel

SWI-Prolog offers a comprehensive Free Software Prolog environment, licensed under the Lesser GNU Public License.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 employed. It is allready available in Ubuntu/Debian repsitory and could be installed by

$ apt-get install swi-prolog






orbits(moon, earth).

orbits(phobos, mars).

orbits(deimos, mars).



planet(P) :- orbits(P,sun).

satellite(S) :- orbits(S,P),


Save as solar.pl

Move to terminal and type prolog. It will give a prolog prompt(?- )in terminal

To run first type

?- consult(solar).

% test compiled 0.00 sec, -116 bytes


?- planet(Who).

Who = mercury ;

Who = venus ;

Who = earth ;

Who = mars ;

Who = jupiter ;


After each ; it will print the planets name until a false which indicates the end of list. "planet(Who)." specifies the query to the logic. Hope this helps