Up Feedback Search                                                             



How to edit, load and run Prolog programs? 


Edit: Open up your favorite text editor, (gedit, emacs, or vi, refer this quick manual question 1), create a file with .pl extension. For example, I could create a simple prolog program like the following:

teaches(liu, cs, 005).

teaches(liu, cs, 050).

teaches(krish, cs, 290).

teaches(krish, cs, 015).  

Saved with a name: teaches.pl


Type the following at prompt to start the prolog interpreter:

% pl 

The following message should pop up:  

Welcome to SWI-Prolog (Multi-threaded, Version 5.2.13)

Copyright (c) 1990-2003 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).


And also a ?- prompt, means ready to go


Load: Type the following to load our prolog program:

?- consult(teaches). 

 A “yes” should follow up, which says prolog successfully loaded the file and is ready to take queries. 


Run: I have had some simple queries for my prolog program, here is the screen snap shot:

?- teaches(X,cs, 005). 

X = liu 


?- teaches(krish, Dep, Course). 

Dep = cs

Course = 290 ; 

Dep = cs

Course = 15 ; 





Use ctrl-d to exit prolog.  Interested in more?  Contact Dr. Doboli


Send mail to cscyzl@hofstra.edu with questions or comments about this web site.
Last modified: 09/16/04