% File if.pl

% if_then_else(A,B,C) is the Prolog version of the 
% conditional statement of imperative and functional languages.
% Intuitively, 
% if_then_else(A,B,C) reduces to the evaluation of B if A is true, 
% and reduces to the evaluation of C if A is false

if_then_else(A,B,_) :- A, !, B.
if_then_else(_,_,C) :- C.

% Sample session

/* 
?- consult('if.pl').
if.pl compiled, 0.00 sec, 556 bytes.

Yes
?- X = 5, if_then_else(X>4, Y=0, Y=1).

X = 5
Y = 0 ;

No
?- X = 3, if_then_else(X>4, Y=0, Y=1).

X = 3
Y = 1 ;

No
?- 
*/
