Update: regrettably, I forgot to include Cookbook.pm in the manifest. 0.732 is now on its way.
AI::Prolog 0.73 is now on its way to a CPAN mirror near you.
Once again, we have a release I'm quite excited about. There's been a lot of work to clean up the output to make it easier to understand. For example, in previous versions, run the aiprolog shell and consult a file containing the following Prolog code:
append([],X,X). append([W|X], Y, [W|Z]) :- append(X,Y,Z).
Then, in the shell, type "listing.". You should get output similar to this:
1. append/3: append([],_0,_0). append([_0|_1],_2,[_0|_3]) :- [append(_1,_2,_3)].
That's really ugly. The /_\d+/ represents variables. Further, in a rule, the list of terms all appear on the same line for a given clause. That can make it very difficult to read. In 0.73, doing the same thing results in this:
1. append/3: append([], A, A). append([A|B], C, [A|D]) :- append(B, C, D).
That's much easier to read.
However, that's not the good stuff. I've now included the AI::Prolog::Cookbook. This document only has a few "recipes", but it does provide a few Prolog solutions of common problems. Here's a Prolog implementation of the quicksort algorithm:
Quicksort
Usage:
sort(List, Sorted).
This definition depends on the
partition/4
andappend/3
predicates defined in this document.sort([], []). sort([Head|Tail], Sorted) :- partition(Head, Tail, LHS, RHS), sort(LHS, Temp1), sort(RHS, Temp2), append(Temp1, [Head|Temp2], Sorted).Note that (currently) this will only sort numeric values.
The cookbook presents many recipes "as is". Other recipes have moderately extensive discussions about important caveats related to them. For example, there's a comparison of the "reverse accumulate" algorithm which runs in O(n) time and the "Naive reverse" algorithm which runs in O(n^2) time.