Prolog 程序实际上是“如果”和“那么”的大条件,后者打印“目标已达到”,而后者打印“没有找到解决方案”。A, B表示“ A 为真,B 为真”,如果不能到达“ A”,大多数 prolog 系统将不会尝试满足“ B”(例如,当 X = 3时,X=3, write('X is 3'),nl将打印“ X 为3”,如果 X = 2则什么也不做)。
?- use_module(library(reif)).
?- if_( ( Ch = a ; Ch = b ), Class = ab , Class = other ).
Ch = a, Class = ab
; Ch = b, Class = ab
; Class = other,
dif(Ch, a), dif(Ch, b).
注意,所有的 if_/3都被编译成一个广泛嵌套的 if-then-else for
char_class(Ch, Class) :-
if_( ( Ch = a ; Ch = b ), Class = ab , Class = other ).