A quick look at using Prolog with VSCode
2025-02-09
Today's article is another one born from my practical needs to install a rather obscure piece of software for university and work my way around a few obstacles. This time we are talking about locally installing a modern Prolog interpreter and integrating it with VSCode for a nice development environment (a similar IntelliJ plugin sadly isn't available anymore)...
If you need Prolog, you probably already know what it is used for, but just in case you got here out of curiosity here's a quick a introduction. Prolog is a logic programming language, meaning that as a subset of declarative programming languages it differs quite a bit from our popular imperative programming languages and focuses more on the What instead of the How. This means that a programmer mostly has to provide an exact description of the problem to solve and the system will resolve it automatically. This can be rather perplexing for our programmer brains that are mostly used to imperative C-like languages - especially if you had nothing to do in the past with the principles of first-order logic it is based on.
Whatever it might be, here's how to install and get it running:
-
irst you have to install a modern version of the free SWI-Prolog distribution either via your
distribution's package manager (e.g.
sudo apt install swi-prolog
on Debian-based systems) or the official website , if you are on Windows. -
Once that is done and you already have a modern version of VSCode (or its free VSCodium
distribution) running, search for the
New-VSC-Prolog plugin
in the
Extensions
tab and install it. Alternatively, this can be done via the command line viacode --install-extension amauryrabouan.new-vsc-prolog
(orcodium
respectively), at least here on my Linux system. -
Now you can create a new folder with a
.pl
file in it and start writing your first Prolog program. Executing it is as simple as hittingAlt-X
and thenL
or executing theProlog: load document
command from the command pallet.
Since that was so fun, here are a few more helpful notes for using it:
-
If you are on Windows and encounter an error message instead of executing your program, you might
have to manually set the
Exectubale Path
in the extension settings to your installation location (usuallyC:\Progam Files\swipl\bin\swipl.exe
). -
To exit the interpreter, simply hit
Ctrl-C
and thenE
. -
At least on Unix systems, you can clear the screen via the
tty_clear.
command. -
To see the next line of a multi-line answer, simply hit
N
(Enter
will just end this query ahead of completion). -
It is absolutely normal to see a final
false
on a multi-line answer as it indicates the end of all solutions - no need to worry.
Just like last week with MATLAB, I truly hope you never have to use this software though, since it is mostly an esoteric language with rather limited real-world use and can be quite a source of headaches. But as always, feel free to share your thoughts and experiences in the comments down below and have a lovely day...