Understanding Bratko `translate` predicate

Relationships are often nouns, thus why nouns make more sense and created to work in both directions. If a predicate has two arguments either one can be ground and the predicate should work. If neither is ground then all the values for the predicate will be listed.

The reason the code from the book is using verbs, translate and transform is because it is not working in both directions, it is a function that takes in one pattern and returns a pattern so the first argument is to be ground and the second argument is to be a variable.

It is not an absolute rule. But if you can see how to change your verb thinking for a predicate into a noun then you will start to think more in relationships and the Prolog code will be better.

There are hundreds of them in the SWI-Prolog code in the GitHub repository. The code in there is often the inspiration for most of my better Prolog.

1 Like

An alternative to the cut operator ( !) - but only in SWI-Prolog (or Picat), is the => or “single-sided unification”. It is documented here. This allows an if-then-else style of rules (similar to how Haskell pattern matching works, with a “catch-all”.

Prolog also has an if-then-else, which is often cleaner than a cut. it’s documented here. And there’s a semi-backtrackable version: (*->)/2.

1 Like