I'm working on defining the logical operators in Prolog as an exercise. The first few were pretty straight forward:
and(A, B) :-
A, B.
or(true).
or(A, _) :-
or(A).
or(_, B) :-
or(B).
neg(false).
But now I want to define nand
and nor
, and it would be nice to define them in terms of my other predicates. For example, maybe something like below:
nand(A, B) :-
neg(and(A, B)).
But the inner and
expression doesn't evaluate. I'm guessing that Prolog interprets the and
expression as an atom. Is there any way to force it to evaluate the nested predicate?