Re: Prolog-style pattern matching in Java. How to?
Ulrich Scholz wrote:
I enjoy programming (and thinking) in Prolog but the reality requires
Java. Now I try to use the best of the former with the latter.
Backtracking can be simulated in Java via enumerators so that seems to
be no problem.
But how to realize Prolog-style pattern matching? A gigant if-then-
else of case construct is too complex and confusing; a solution via
reflection seems to be unefficient.
Any ideas, suggestions? Literature references?
My suggestion is to backtrack. You presumably have a problem you are
trying to solve, for which Prolog backtracking and pattern matching is a
local optimum. Now you want a Java solution, so you need to leave that
point. Retaining the "Prolog-style pattern matching" idea limits the new
search to a subspace of the Java program design space that somehow
reproduces a Prolog design pattern.
Maybe that subspace includes a really good Java solution to your
problem. Maybe it doesn't. But without backtracking in your design
thinking you will not be able to see if there is a better Java solution
outside the "Java implementation of Prolog-style pattern matching" subspace.
If you are going to code well in Java, not Prolog, you need to think in
Java, not Prolog.
Natural language translation provides another way of seeing this issue.
Suppose I say "I am going to go to the movie theater that finds itself
in the Westview shopping center". It is very stilted, awkward English.
However, "that finds itself" is a literal translation of "qui se trouve"
an idiom that sounds perfectly natural in French. You are in danger of
writing, in Java, literal translations of Prolog idioms.
Patricia