Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using prolog with emacs

GNU Emacs 23.2.1
Fedora xfce 14

I starting to get into Prolog, and I want to use my emacs as the IDE for programming in Prolog.

Currently I use emacs for c/c++. But not sure how to get started with Prolog. I know that emacs has a built in library for programming in emacs. However, I have researched and found it is feature less, i.e. no syntax highlighting, indention, etc.

So I have download the emacs prackage Prolog.el. I have loaded this library using M-X Load-library.

However, I am not sure what to do after that. How do I compile my prolog files? In the menu of the emacs IDE it has nothing for Prolog.

Do I also need to download some interpretor or compiler for Prolog? Is there an emacs command for compiling? I normally use make in emacs when compiling c code.

I did a yum search prolog and got these results, so with all these choices which one do I need?:

gprolog.x86_64 : GNU Prolog is a free Prolog compiler
pl.x86_64 : SWI-Prolog - Edinburgh compatible Prolog compiler
pl-static.x86_64 : Static library for SWI Prolog
ppl-gprolog.x86_64 : The GNU Prolog interface of the Parma Polyhedra Library
ppl-gprolog-static.x86_64 : The static archive for the GNU Prolog interface of the Parma Polyhedra Library
ppl-swiprolog.x86_64 : The SWI-Prolog interface of the Parma Polyhedra Library
ppl-swiprolog-static.x86_64 : The static archive for the SWI-Prolog interface of the Parma Polyhedra Library
ppl-yap.x86_64 : The YAP Prolog interface of the Parma Polyhedra Library
yap.i686 : High-performance Prolog Compiler
yap.x86_64 : High-performance Prolog Compiler

Many thanks for any suggestions,

================== EDIT =====================

I have installed the following pl.x86_64

I have download the prolog.el and put it the following directory:

~/.emacs.d/site-lisp/prolog/prolog.el

And I have configured my emacs with the following:

;;; Prolog mode
(setq load-path (cons "~/.emacs.d/site-lisp/prolog/prolog.el" load-path))
(autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
(autoload 'prolog-mode "prolog" "Major mode for editing prolog programs." t)
(setq prolog-system 'swi) ; prolog-system below for possible values
(setq auto-mode-alist (append '(("\\.pl$" . prolog-mode))
                              auto-mode-alist))

So when I save a file as *.pl I get the prolog menu options.

So I write some prolog code and from the prolog menu, I select Run interactive prolog session

I get a second blank buffer open which says (Inferior Prolog:run Shell-Compile)

However, I am not sure what I need to do at this stage. How do I compile and run the prolog files?

Many thanks for any further support.

like image 321
ant2009 Avatar asked Mar 13 '11 07:03

ant2009


3 Answers

Another alternative with a nice emacs mode is Ciao.

like image 118
A.Robinson Avatar answered Oct 19 '22 21:10

A.Robinson


You are not using the intended advanced prolog.el, since your load path is wrong. It should read:

(setq load-path (cons "~/.emacs.d/site-lisp/prolog/" load-path))

notice that I removed prolog.el from the end of the path. Actually, it should even better read:

(add-to-list 'load-path  "~/.emacs.d/site-lisp/prolog/")

Then start Emacs again, and it should give you a menu with many more options. (Try C-h v prolog-mode-version, which only works with the advanced mode, and shows its version number.)

You can then try C-c C-b to consult the buffer etc. Also consider using ediprolog, with which you can evaluate queries directly in the Emacs buffer. Notice also that in recent Emacs versions, a variant of the advanced Prolog mode is the new default, but it unfortunately ships with severe regressions and flaws so that I recommend the original version maintained by Stefan Bruda:

https://bruda.ca/emacs/prolog_mode_for_emacs

For more information about Prolog and Emacs, see Using SWI-Prolog with GNU Emacs.

like image 21
mat Avatar answered Oct 19 '22 23:10

mat


You need a Prolog environment, such as SWI-Prolog, GNU-Prolog or YAP. I think that SWI is very commonly used, but I can't tell if it's better than others. You don't need to compile Prolog files in order to run them - Prolog can work as an interpreter (interactive compiler, in some cases). To load a file into the Prolog environment you need to consult it. When in Prolog mode, emacs can do that with C-c C-f. You can also type directly from the Prolog shell consult(File).

like image 37
Little Bobby Tables Avatar answered Oct 19 '22 23:10

Little Bobby Tables