..

The Art of Prolog by Leon Sterling and Ehud Shapiro

In my never-ending quest to broaden my knowledge of programming idioms, I finally decided to give Prolog a try. I read many forum posts and reviews about the topic, and one of the books most often sited was The Art of Prolog by Sterling and Shapio.

This was an amazing book not just because it teaches you how to program in Prolog, but because it explains Prolog’s foundation: Logic Programming. In fact the entire first section covers Logic Programming, all without one line of pure Prolog code. Learning about Logic programming first helps one to understand Prolog’s capabilities and shortcomings. In essence, you learn to acknowledge what Prolog strives to be and what it can do.

Learning about Prolog is fun because it introduces you to completely new vantage points to problems. Consider this naive example of expressing the relation reverse:

<pre>reverse([],[]).

reverse([X
Xs],Zs) &#x2190 reverse(Xs,Ys), append(Ys,[X],Zs)</pre>

The first line says that calling the goal reverse with two empty lists succeeds. The second line says that calling the goal reverse with two parameters, the first being the list comprised of the element X followed by the rest of the list Xs and the second being the list Zs, will succeed if there exists a list Ys that is the reverse of Xs and the element X appended to that list Ys produces Zs. Calling this relation with the first parameter set to a value and the second a variable will set the variable to the reverse of the value. With Prolog’s unification, that is all that is needed for it to find a solution.

This book is a terrific mind exercise far different from any imperative language. This book covers the basics of Logic programs, enough Prolog to get you started and explains some complex, real world applications built with Prolog. I am an advocate of using the best tool for the job, and Logic programming is a great tool to have for a developer.