Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog Programming in Ubuntu

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)?

like image 726
octain Avatar asked Dec 07 '13 23:12

octain


People also ask

How do I open Prolog in terminal?

Now to open the Prolog complier write command swipl. Now to load the simple.pl file type ['simple.pl']. in the compiler terminal. The “.” at the end of ['simple.pl']. is used to mark the end of the command in Prolog.


2 Answers

On Ubunutu, I started off using emacs, which at least does syntax highlighting:

http://www.swi-prolog.org/FAQ/GnuEmacs.html

(2 emacs suggestions on that page ^)

But now I use prolog in anger, I use an Eclipse plugin called PDT:

http://sewiki.iai.uni-bonn.de/research/pdt/docs/v2.1/start

Especially useful is the real-time line by line debug and trace, so you can step into, step over individual predicates, monitor variables names etc.. just like an other real IDE you would find in eclipse.

Probably only worth installing if you're going to use it a LOT, since the install is a lot of work, but it's a great IDE.

But if you like your low level editors like VIM, you will have to use the debug and trace tools built into swi-prolog, see:

http://www.swi-prolog.org/pldoc/man?section=debugger

To work out how the strange and beautiful prolog interpreter works, using a tracer of some kind is a must-have.

like image 21
magus Avatar answered Sep 18 '22 23:09

magus


Yes, you can use any text editor, incl. VIM. Once you have written a Prolog source file, say, file.pl, you can load it into SWI-Prolog like so:

swipl -s file.pl 

This will compile your file and take you to an interactive shell where you can then ask queries against the definitions in your file.

If you want to use your Prolog program in batch mode, you can use:

swipl -s file.pl -t goal 

where goal is the goal/query you want to evaluate. Note that in this case you won't be getting the option to ask for alternative solutions.

like image 107
Christian Fritz Avatar answered Sep 18 '22 23:09

Christian Fritz