The β / 2 is required only if you want to impose a certain determinism. It acts as a local incision. But if you want your code to maintain some non-determinism, there is no need to use β / 2.
Take the following imperative code:
boolean listOfBool(Object obj) { if (obj instanceof ConsCell) { if (((ConsCell)ob).head() instanceof Boolean) { return listOfBool(((ConsCell)ob).tail()); } else { return false; } } else if (obj == null) { return true; } else { return false; }
}
This can be encoded in Prolog without β / 2 as follows:
% bool(+Bool) % bool(-Bool) bool(0). bool(1). % list_of_bool(+List) % list_of_bool(-List) list_of_bool(L) :- (L = [X|Y], bool(X), list_of_bool(Y); L = []).
The advantage is that it can be used to check boolean lists and generate boolean lists:
?- list_of_bool([0,1,0]). Yes ?- list_of_bool([0,1,2]). No ?- List=[_,_,_], list_of_bool(List). List = [0, 0, 0] ; List = [0, 0, 1] ; List = [0, 1, 0] ; List = [0, 1, 1] Etc..
In the general case, the disjunction (;) / 2 can be distributed over multiple entries. If this is combined with moving the union (=) / 2 to the head, then you can get some speed, since then the predicate is usually better indexed.
Here's what an alternative list_of_bool would look like, for example, by excluding (;) / 2 and (=) / 2:
% list_of_bool2(+List) % list_of_bool2(-List) list_of_bool2([X|Y]) :- bool(X), list_of_bool2(Y). list_of_bool2([]).
The above works in exactly the same way (it really works better since there is no choice point left in the first request that (;) / 2 is usually not detected without (->) / 2):
?- list_of_bool2([0,1,0]). Yes ?- list_of_bool2([0,1,2]). No ?- List=[_,_,_], list_of_bool(List). List = [0, 0, 0] ; List = [0, 0, 1] ; List = [0, 1, 0] ; List = [0, 1, 1] Etc..
It is also possible to launch Prolog. Only with the rules and no disjunction (;) / 2 and without unification (=) / 2. the later two already exist in the basic positions of Horn.
Suppose you have a Prolog without (;) / 2 and no (=) / 2, and you do not need a transparent (;) / 2 section, then you can define these constructions by yourself:
X = X. (A ; _) :- A. (_ ; B) :- B.
Bye
Horn Point
http://en.wikipedia.org/wiki/Horn_clause