On a quest for the silver bullet..

Prolog within Java

Last night I attended a meeting at my local java user group. The theme of the presentation was actually Prolog, and a Prolog-framework for Java was presented.

I enjoy learning different ways to solve (the same) problems,  and I strongly believe it is important to do that. Seeing other ways to solve common problems will help expand your mind as to how you can solve problems yourself. That’s why i found this meeting so interesting too. Maybe I will not use Prolog so much myself, but I can still learn from it’s way of thinking, and enrich both my thinking and my code written in other languages.

Prolog 

Well, back to Prolog. I haven’t really been introduced to Prolog before, so I enjoyed the introduction we got. Three things strike me with Prolog:

1) How different it is from other mainstream programming languages.  Here we have a language that actually does not contain an “if”-statement, and it still solves problems. I find that fascinating in itself. It’s a completely different way to solve problems.

2) How declarative and explicit it is about the (domain) rules. Given a well defined domain I would love to express the rules for that domain in Prolog. It’s really beautiful.

3) It must be a nightmare to debug. When your ruleset and dataset starts to grow, it must be a nightmare to debug and even worse to try to make changes to it.

Java and Prolog (jTrolog)

Given my observations about Prolog are “correct”, I believe Prolog can be a beautiful tool, but I think the domain must be small and specific. And given that many of us normally work on enterprise applications with not so small and well defined domains, maybe Prolog is not the thing.

But then again, what if we find smaller well defined sub-domains within those enterprise applications?

Enter jTrolog (or one of it’s equivalents). jTrolog let’s you define and execute Prolog in plain Java. What I see here is opportunity. Now we can still make our enterprise applications in Java, but all of a sudden we can introduce the elegance of Prolog for specific sub-domains.

When it comes to it, it’s ofcourse not just that easy to introduce Prolog in your next Java project. For instance, introducing a new language that probably no one else on the project understands well, will most often not be a smart thing to do. But such barriers are there to be overcome.

Expand the horizon!

- Tore Vestues

February 15th, 2008 at 9:32 (439)


One Response to “Prolog within Java”

  1. mat Says:

    Regarding debugging of Prolog programs: There are quite sophisticated tools that help with that. For example, in SWI-Prolog, try:

    ?- gtrace, YourGoal.

    to graphically step through your code. Almost all Prologs ship with the textual “trace” command, and often other tools that help a lot. For several large real-life applications from many areas that are written in Prolog, see for example the SICStus Prolog site, or the projects written in SWI.

Leave a Reply