Prolog as a Specification Language?
2022 03 07
I’ve been writing quite a lot of Prolog for work, and it’s got me thinking about possible alternative uses of the language. If you haven’t used Prolog before, Prolog is a functional, declarative, logic-based programming language. Instead of telling the computer what to do, you tell it what should hold as true.
For the curious, at work we generate Prolog databases from some of our data and have written Prolog rules to determine the compatibility of some complex product sets. It’s an interesting solution to the problem, and I think it’s saved us a lot of coding in more traditional languages.
But back to the point.
It had been a long day in the Prolog mines, tweaking rules and defining predicates, and after my tea I set down for a treat — I opened up Fraidycat and skimmed through some blog posts and articles. Long story short, I came across Pantagruel, a specification language.
Even though a large part of Pantagruel went over my head, it did make me think – what if I used Prolog as a specification language?
I don’t want to get too deep into what specification languages are here, so I’ll be lazy and link to the wikipedia page.
I’ve played with Alloy and with TLA+ a couple of times, but never stuck with them for very long. They’re quite abstract, and I fear that I’ll bounce of them more than once before I understand enough for them to be useful.
I think Prolog might make a slightly different kind of specification language than Alloy or TLA+, though. Instead of describing a model out of Objects or Sets, you might describe what should hold true if the specification is to be achieved. Using back-tracking, you may even then be able to generate possible solutions to your specification and double-check that they work for you.
I don’t really know what a specification would look like in Prolog. I’m not entirely sure where I should start, or what I would want to specify. But I’m going to attempt to put some time aside to think about it a bit. My usual pattern will likely result in me coming back to the idea after months and months and chipping away just a bit, only to start the cycle again. But it is an interesting thought.