Prolog / Emacs

Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.

Prolog / Emacs
Hello,

in order to get prolog working on my Windows 10, i followed the steps given in the notes https://kwarc.info/teaching/AI/notes-part1.pdf (page 10).

Now i have installed both prolog and emacs, however i can not understand, how should i get it working the prolog with emacs…
To be more precise, this paragraph:

Now, once you’re in emacs, you will need to figure out what your “meta” key is. Usually its the alt
key. (Type “control” key together with “h” to get help on using emacs). So you’ll need a “meta−X”
command, then type “run−prolog”. In other words, type the meta key, type “x”, then there will
be a little window at the bottom of your emacs window with “M−x”, where you type run−prolog3
.
This will start up the SWI ProLog interpreter, . . . et voilà!

Can you please help me with additional info?


When you have opened Emacs, you can press Alt-x (usually designated as [m]M-x[/m]) to run an interactive command. One such command is called [m]run-prolog[/m], followed by pressing the enter key. That starts an interpreter, which will Emacs communicate with.

The GNU Website has a good tour of Emacs, and it’s basic usage: https://www.gnu.org/software/emacs/tour/index.html. It might take half an hour to get used to it, but it’s not that difficult – just different. Either way, it’s certainly worth it!

Btw. the configuration mentioned in the notes is not up to date, in modern versions of Emacs (ie. anything that has been released in the last ~10 years), the following should suffice:

(setq prolog-system 'swi)
(add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))

This tells Emacs to use SWI Prolog and regard file names ending in [m].pl[/m] as Prolog files, improving the interaction between files and the interpreter.

Edit: SWI-Prolog appears to bundle it’s own Emacs-like editor: https://www.swi-prolog.org/PceEmacs.html. On Windows it should use CUA keybindings, but that’s fixable. This page also has a few more interesting notes on Emacs and Prolog: https://www.metalevel.at/pceprolog/


Dear Students,

I did not want to overly push emacs on you. It is just the editor I use almost exclusively for the last 30 years, and I know (knew as it turns out) the invocations to turn on emacs mode. I would be very happy to add instructions for other editors or IDEs to the notes. So if there is one you like and want to see there, please send me instructions.


Hello,

thanks for the help! I think i am only one/few step/s away from working prolog!

Now when i type in “run-prolog” a new window on the right side opens. However when i write prolog “code” there it gives a mistake… Can you please tell me what i need to do now?

See picture .

Thanks!

Attachment:
1.PNG: https://fsi.cs.fau.de/unb-attachments/post_165356/1.PNG


The new window displays the the SWI Prolog process, you need a seperate file/buffer (a buffer is a file in memory) for the actual Prolog clauses.
You can either use the GUI to create a new buffer, or type [m]C-x o[/m] to focus an other window (you can do the same thing using your mouse), followed by [m]C-x C-f[/m] to find/create a file and open it. You’ll have to enter the name of the file you want to use, and press enter again.
In case you haven’t configured anything, Emacs will only interpret this file as a prolog file, if the extention is “.prolog”. You can manually tell Emacs what kind of a file you are working on using [m]M-x prolog-mode[/m].
Now you have additional keybindings, such as a few that allow you to send your code to the Prolog process. For example, by tying [m]C-c C-b[/m] the whole buffer is loaded into Prolog, and you can query it in the [m]prolog[/m] buffer. You can do the same for a single single predicate using [m]C-c C-p[/m], etc.
A list of all commands will be generated by [m]C-h m[/m] (“help me with this mode”), but I don’t think you have to learn about Emacs’ self-documentation system to use Prolog.