开发者

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 f开发者_开发技巧iles?

Many thanks for any further support.


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.


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


Another alternative with a nice emacs mode is Ciao.


A more complete prolog mode can be found here: Prolog mode for (X)Emacs If you search the .el file for the string prolog-mode-keybindings or do a C-h b while in prolog mode you can see what is available.

If you install pl.x86_64: You can also use the SWI Prolog builtin editor called PceEmacs, see here: The SWI-Prolog builtin editor: PceEmacs SWI Prolog is very complete and includes a text-based debugger in addition to a graphical debugger The graphical tracer and its own GUI system The XPCE GUI system for Prolog plus a lot of libraries. It is a great prolog for exploration. If you want to instead use SWI Prolog with emacs, here is the setup Using SWI-Prolog with GNU-Emacs


  1. Read carefully the installation instructions for prolog.pl -- http://bruda.ca/emacs-prolog/install.html

  2. Echoing what 'mat' wrote on March 20, use `add-to-list' instead of `setq':

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

    This is the "modern" usage, and should be a bit clearer to you than the `setq' construction.

  3. I haven't read the prolog.el code from bruda.ca carefully, but it does look a little dated. However, it also looks like it has many more features than the code included with GNU Emacs. I do not know whether the additional features will outweigh the agedness of the code. It appears that the bruda.ca code is derived from an earlier version of the GNU Emacs prolog.el, as stated in the comments in the bruda.ca code.

  4. Once you have corrected the value of the `load-path' variable (it is analogous to the PATH environment variable), prolog.el should load correctly. Because there is no documentation file for prolog.el, here are some Emacs commands you can use to begin exploring prolog mode:

    C-h m -- This will display help to list the key bindings that have been defined for prolog-mode, as well as any other minor modes that you might have in effect.

    C-h a prolog -- This will display help to list (interactive) commands that have been defined by prolog-mode (prolog.el).

    If you have not turned off menus, then a menu entry for prolog should be available whenever you open a file in prolog mode.

  5. Finally, there is always reading prolog.el (at the very least, the descriptive comments at the top of the file). (The second half of the file is listed as experimental code.) It would be good if this could be updated and added to the prolog.el that is included in GNU Emacs.


You need a compiler for Prolog, so you got to install one of the listed compilers. Then, I suppose you write a Makefile and call it through M-x compile.


If you're using the Emacs package manager, you can type M-x package-install RET prolog, and then reload Emacs.

Simple and works.

I use Fedora 15, but Emacs is its own operating system.


Go into swi-prolog command line and type:

emacs.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜