Prolog Programming in Ubuntu

Viewed 38126

I have an interest in playing and fuxing with prolog, I have installed the swi-prolog and added the repository, just in case anyone is interested on which one commands I used:

% sudo apt-add-repository ppa:swi-prolog/stable
% sudo apt-get update
% sudo apt-get install swi-prolog

How do I actually begin to write prolog codes on my linux machine? for my regular programming I use VIM to write/edit/debug and terminal to compile. Can I use vim to write prolog? How do i compile or use the prolog interpreter(i think that is what it is called)?

6 Answers

buddy I also use vim to edit prolog code, What I personally do is I save my prolog file with the '.pl' extension, and then on the terminal, I use prolog interactive environment to consult my file e.g:

To initiate a prolog interactive environment just type On terminal:

prolog

Now that you have entered in SWI-prolog you can use 'consult' i.e pre-defined pseudo-predicates allow one to load Prolog code into a running Prolog interpreter:

?- consult("filename.pl")

that's it!

You can use any text editor to write your code. Just make sure to save your code with the .pl extension like fibo.pl. After that open the terminal and go to the location where you have saved your code. After that type prolog After that write the name of your file without .pl extension and end it with . ['fibo']. and press return

Eg - cd /home/student/14917
prolog
['fibo'].


Here fibo.pl is my program name

I use SWI prolog with Sublime Text on mac. Works really nice. In Sublime Text you just hit cmd - B to run the code, and the output appears in a window within Sublime Text. There is a package for it here.

Related