Windows & .NET Watch: The truth of Prolog
June 15, 2010 —
(Page 1 of 3)
In recent columns, I’ve praised the low-level pleasures of assembly language and C. My argument is that, even if you never use these languages professionally, it’s important to broaden your mind and problem-solving techniques. That holds not just for low-level approaches, but for other programming models whose high-level abstractions are different than you’re likely to work with every day.
Prolog stands for “Programming in Logic.” The hey-day of Prolog—to the extent it had one—was the mid-1980s, when it was briefly in vogue in the artificial intelligence community (Prolog was to Lisp what Ruby is to C# and Java? Maybe). Japan picked Prolog as the implementation language of its “Fifth-Generation” computing project, and Borland’s Turbo Prolog was a low-cost IDE and compiler that made the language accessible to a broader audience. Today, there are a few commercial Prologs, but the simplest way to explore it is with GNU Prolog.
Program execution in Prolog is considerably different than in any of today’s mainstream languages. The Prolog interpreter (or compiler runtime) actually seeks a goal: a clause (the equivalent of a function or block) for which the current data makes every statement in the clause true. Execution can be halfway down a clause before it hits a statement that is false, at which point it backtracks and tries to find a different clause that is true for the data.
For instance, if you were trying to categorize animals in the traditional manner, you might say that a mammal is an animal that has a backbone, breathes air and has hair, while a bony fish is an animal that has a backbone, breathes with gills, has a bony skeleton, and so forth. Programming consists of defining a bunch of such clauses and running it against a database of, in this case, specimens in your zoo.
The interpreter in essence does a search: It begins iterating over the database, taking an item (a_specimen) and a clause (“is_a_mammal”). The first subclauses of “is_a_mammal” ask “is_an_animal” and “has_a_backbone” (both true in the case of the first specimen in the database), but then asks “has_hair,” which is false. The entire clause “is_a_mammal” is therefore false for the first item in the database.
Related Search Term(s): Prolog
Share this link: http://sdt.bz/34423