by hackyhacky · 7y ago · 0 comments
inorderTraversal(t(V, L, R), Z) :- inorderTraversal(L, Z).
inorderTraversal(t(V, L, R), V).
inorderTraversal(t(V, L, R), Z) :- inorderTraversal(R, Z).
Also, the meaning of ordering of goals with a rule may be significant: ?- not(member(X,[a,b,c])), X=f.
false.
?- X=f, not(member(X,[a,b,c])).
X = f.
Although Prolog aspires to represent logic, it is still really just a logic-flavored programming language.As to the examples using not/1: This is an extra-logical predicate where this flexibility indeed does not apply, since its meaning depends on the evaluation strategy.
However, for this concrete case, we can use the purely logical predicate memberd_t/3 to retain desirable logical properties such as commutativity of conjunction:
?- memberd_t(X, [a,b,c], true), X = f.
false.
?- X = f, memberd_t(X, [a,b,c], true).
false.
memberd_t/3 is available in library(reif) for various Prolog systems.Yes, but Prolog specifies a particular concrete evaluation strategy, and you have to rely on it to write practical programs.
For example, an increasing number of Prolog systems provide, in addition to SLDNF resolution (which is the the default evaluation strategy), also SLG resolution (tabling) as an evaluation strategy with different termination and performance characteristics.
These different strategies are very useful in practical programs, and it would be limiting if one were to prevent them by using extra-logical predicates.