数学计算: X is <数学表达式> 数学运算: +-*/ () 比较运算: X > Y X < Y X >= Y X =< Y
1 ?- X is 1*2+3/4-(5-6)*7. X = 9.75. 2 ?- 3=<4. true. 3 ?- 3>=4. false. 4 ?- 3>4. false. 5 ?- 3<4. true. 6 ?- X is 2+2, 3>=X. false.
看一下摄氏度与华氏度互转的程序:
%swipl -s calc.pl %Hansen c_to_f(C,F) :- F is C*9/5+32. f_to_c(F,C) :- C is (F-32)*5/9.
1 ?- c_to_f(11,F). F = 51.8. 2 ?- f_to_c(51.8,F). F = 10.999999999999998.