Frontier Software

Prolog Cookbook

By Robert Laing

These are notes I’ve made for myself and anyone else interested as I explore logic programming with Prolog, specifically SWI Prolog.

I originally created this website using MoinMoin, but have now moved it to Hugo thanks to its fantastic syntax highlighting which includes support for Prolog and just about every other programing language and data format.

I’m finding a static site generator as opposed to the various content management systems I’ve dabbled with over the years a pleasure since it doesn’t get in the way of using third party JavaScript libraries. So far, I’ve used vis.js to draw graphs I originally did with graphviz.

I’ve also played with MathJax to try fool people with intimidating maths into thinking I know what I’m talking about.

I’m in the process of rewriting the various puzzles etc that were here in MoinMoin to the new format. As we say in South Africa, it will be here again “now now”.

If you have any suggestions or corrections, please post them to a thread I started on SWI Prolog’s discourse forum.

Documenting, testing, and moduling

By Robert Laing A nice thing about Prolog, specifically SWI Prolog, is there isn’t the cacophony of competing document generating systems, unit testing frameworks etc as there are for, say, JavaScript. Nevertheless, getting to grips with PLDoc, PLUnit, along with SWI Prolog’s modules etc is not that easy, so I’ve made these notes for myself and anyone else interested. The very basics of PLDoc is it can be launched as a web server either from within the swipl repl with doc_server(4000).

Game Trees

By Robert Laing Glossary AnalysisAssumes what is required to be done is already done. What is sought as already found, what we have to prove as true. AntecedentA thing that existed before or logically precedes another. My introduction to this was via a free online course, General Game Playing, which offers a nice selection of games written in a Lisp-dialect called KIF which is fairly easy to translate into Prolog. The games follow a template called Game Description Language.

Graph Traversal

By Robert Laing Traversing trees comes up a lot in coding. For intance, I needed to write a recursive HTML template to generate the table of the contents on the left of this web page using Hugo, and I posted my solution to Hugo’s discourse group for anyone interested. The pattern I followed is called a transitive closure. Whenever I need some computer science theory, I turn to a textbook written by Turing Award winners Al Aho and Jeff Ullman which they have kindly made freely available online.

Puzzle Solving

A fun application of graph traversal, specifically route finding, is using Prolog to solve puzzles. A basic framework for representing games in Prolog has been provided by Stanford University’s General Game Playing course. The notes for the course written by Michael Genesereth include A Brief Introduction to Basic Logic Programming. There are two dialects of Game Description Language, infix GDL which is nearly identical to Prolog, and a Lisp-like prefix GDL, called Knowledge Interchange Format, which is what the many examples provided at its public game repositories are written in.