Day 3 - Prolog
Day 3 - Prolog
Join the DZone community and get the full member experience.Join For Free
Prolog is the 3rd language covered in Bruce Tate's Seven Languages in Seven Weeks, and is a declarative, rather than imperative, language. Prolog is not new, of course (1972), but I have to admit this is the first time I've taken a look at it.
Like Bruce, I used GNU Prolog (1.3.1). As he describes the language, the building blocks are facts and rules (which together form a knowledge base), and queries. He describes some simple queries, then moves on to substituting variables in queries. He finishes the first day of the Prolog segment with a discussion of Prolog unification, then an interview with Brian Tarbox, a dolphin researcher who used Prolog both to simulate dolphin behavior and to schedule the personnel needed for each dolphin experiment. According to Tarbox, Prolog was very well suited for solving both types of problems.
The first day looked at declaring facts and rules and making simple queries against them. Day 2 adds some more tools, including recursion, math functions, and lists and tuples (and operations on them). Day 2 is the day where my experiment in covering one language per day seems the least feasible; I'm not familiar with declarative (programming) languages and although I get the idea, a lot of it went over my head. Bruce is extremely profuse with examples, deconstructed ones at that. If I wanted to learn Prolog, I would start with this book first and spend a few more days on it.
For Day 3, Bruce goes through two detailed examples -- a solution for a small Sudoku puzzle, and the Eight Queens problem. He then finishes with a discussion of Prolog's strengths and weaknesses, including listing problem spaces for which Prolog is particularly well-suited. Those areas? Scheduling constrained resources, natural-language processing, games, semantic web representation and artificial intelligence.
Opinions expressed by DZone contributors are their own.