Running Prolog on Linux
Hello! I hope you had a nice restful Easter. I've been a bit busy this last 6 months, but I've got a holiday at the moment, and I've just received a lovely email about my learning prolog series. It's reminded me about how much I actually rather like (swi) prolog (I'm a bit nuts, I know :P), and I've decided that it would be splendid if I could get back into it a bit.
I'm not sure whether it'll go anywhere, but I'm going to look into web crawling and parsing HTML. Anyway, since I'm re-discovering prolog, I had a teensy bit of trouble getting prolog to run one of my old scripts just now, so I thought I'd blog about it to save me the trouble next time :D
Running prolog scripts on linux isn't actually that hard. First, you need to install SWI-Prolog:
sudo add-apt-repository ppa:swi-prolog/stable sudo apt install swi-prolog-nox
Then, you run a prolog script like this:
swipl -f ./Awesome-Prolog.pl Welcome to SWI-Prolog (threaded, 64 bits, version 7.4.1) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?-
...then you can interact with your Prolog knowledge bases as normal. When you want to exit, the easiest way I've found is if you press CTRL + D.
If, however, you're lazy and don't want to type
prolog -f AwesomeSauce.pl out every time you want to run your script, you can prefix your file with the following shebang:
Make sure it's the very first line in the file. Prolog appears to ignore it and carry on regardless. Then you can run it like this (making sure you've
chmod +x'd it first: