I'm a software architect/consultant in Boulder, Colorado. I started blogging at: http://wayne-adams.blogspot.com/, but have since started the new blog, Data Sceintist in Training which will cover the areas I am learning as part of my own "big data" training, including the Hadoop family, frameworks like OpenStack, the R programming language, column-oriented databases and the art of examining data sets for useful patterns. The original blog will be kept alive with Java-specific posts. Wayne is a DZone MVB and is not an employee of DZone and has posted 35 posts at DZone. You can read more from them at their website. View Full User Profile

Day 3 - Prolog

04.01.2011
| 4412 views |
  • submit to reddit

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. 

From http://wayne-adams.blogspot.com/2011/03/day-3-prolog.html

Published at DZone with permission of Wayne Adams, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Mihai Dinca - P... replied on Fri, 2011/04/01 - 6:48am

Man, this is JAVA lobby ....

Christian Schli... replied on Sat, 2011/04/02 - 3:27am in response to: Mihai Dinca - Panaitescu

Knowing other languages makes you a better programmer. Prolog is a particularly well choice because it's declarative, not imperative. That is, to solve a problem, you describe the properties of the solution rather than the steps to solve it. The search engine of the Prolog interpreter then computes a solution which satisfies the properties described by you.

This makes Prolog particularly well suited for any kind of problem which can be solved by searching for a solution. I remember I wrote an application in SWI-Prolog which solves the Rubik Cube puzzle. It included a GUI with a 2D and 3D view. The source code was only 64KB - you could never do it this small in Java!

Thanks for posting this series - I like it!

Greg Matoga replied on Sun, 2011/04/03 - 4:54am

I'd like to defend the point presented in the article.
It sure is Java lobby and Prolog seems very departed from anything java related, but You could relate it to Java by means of java rule engine. There's even a Java Rule Engine API - JSR 94 included in Java EE specification. JBoss Drools is one implementation. And You can work with it in quite a similar way You'd do with Prolog. There's also another Java rule engine: JESS which, in my view, seems a bit closer to Prolog.
There's a big room for rules engine in business applications (http://en.wikipedia.org/wiki/Business_rules_engine). Rules Engine is a perfect fit for some business areas, i.e. financial, goverment where laws are changed at leas once a year.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.