3

I'm building a card game called Tijari (uses 40 Spanish cards deck, quite similar to Bridge) as an Expert System. This is all part of my doctoral thesis.

I'm having a hard time finding a good balance between Prolog code and Java code, what would go where and why. The game must let human players play against the AI as well as against each other, so you can have a team of (Human + AI) vs (AI + AI) or (Human + Human) vs (Human + Human) or anything in between.

While Prolog is defined as being about facts and rules, most uses I see of it are not really what you would call logic programming but actually awkward programming trying to implement sometimes complex algorithms under the constraints and intricacies of the language: shuffles, search and complex list operations. Why?

There are some uses of Prolog that a language like Java cannot provide easily like when it comes to deduction based on existing rules and facts and the ability to query for information, still, I generally cannot seem to be able to justify its use.

Is it the fact that it encodes domain knowledge in logic? Well, any real-world Prolog program seems harder to read than plain Java code because of backtracking, cuts and recursion.

Is it the fact that it doesn't require a software developer to encode domain knowledge, just a domain expert? Well not really, you would still need a domain expert who is well versed in Prolog.

Is it the fact that you can easily modify the rules and facts without needing recompilation? Well, any scripting language can offer that really.

Is it the fact that it can easily evolve as domain knowledge evolves? Well, I believe that domain knowledge doesn't evolve that much for it to be a problem, and when it does, software follows, that is why it has always been.

I honestly have a hard time justifying the use of Prolog as the only language in which an Expert System (and here a game) must be built, and when it's not, when you end up using a combination of Java and Prolog, where should the line be?

Thanks

younesouhbi
  • 111
  • 1
  • 8

1 Answers1

3

I think your question is a very good and legitimate question, and I am also quite certain that it will soon be closed as many other interesting and worthwhile Prolog questions already have been.

Therefore, I try to rush in an answer while that is still possible.

First, I would like to point out that many Prolog programs are currently indeed still more awkward than they could be. One of the reasons for this is that the existing teaching material is sometimes decades behind the current state of the language. As a result, many very important declarative features that have become widely available in many systems in the past few years and decades are simple not known by a large fraction of Prolog programmers. With these features, many Prolog programs become a lot less awkward.

One important difference between the two languages is in my experience: In comparison to programming in Prolog, writing Java code is extremely inconvenient. The reason becomes immediately obvious after your first few serious Prolog programs: In Java, you consistently feel at least one step too far removed from the actual task. You cannot simply write down the terms, state, knowledge etc. No, you instead have to first write down a meta-description of the knowledge itself (in the form of classes, types, interfaces), and only then can you talk about what you actually want. But that's not all: The description of both the actual knowledge and its properties is extremely low-level. For example, you cannot conveniently reason about things symbolically via pattern matching.

The benefits of this quite indirect programming style that Java inherently necessitates are in my view very questionable. At least I have yet to see a Java program where I could with a straight face say: "Yes, Java was a great choice for this project." By comparison, I have seen many Prolog programs where Prolog definitely was a great choice for the project.

There are many more differences that make programming in Prolog vastly more convenient than programming in Java. For example:

  • Prolog code is easy to parse, change and analyse by other Prolog programs, allowing for some very cool shortcuts
  • Prolog code is very easy to test interactively using the toplevel
  • Prolog code can often be used in several directions, leading to shorter programs
  • very importantly, it is extremely easy to formulate extensive test cases using comparatively simple Prolog queries which generate a vast number of tests on backtracking.

These are only a few examples I'd like to mention. Overall, I think that if you regard Java as a "general purpose" programming language, then Prolog definitely also falls into that category. At least I have yet to see a project where someone said "It would be so great if only we could use Java for this task!" I've heard this phrase about Prolog several times already.

mat
  • 40,498
  • 3
  • 51
  • 78
  • Well said! Let's try to imitate Java, not (necessarily / primarily) tech details, but sales! – repeat Jun 03 '16 at 22:27