IF-THEN是否以规范形式?

时间:2018-02-03 21:51:43

标签: prolog operator-precedence canonical-form

像这样定义IF:

dynamic(if/1).

op(200,  fx, if).
op(150, xfx, then).
op(100, xfy, and).
op(100, xfy, or).

生成以下规范形式:

?- write_canonical(if x then y).
if(then(x,y))

?- write_canonical(if x and  z then y).
if(then(and(x,z),y))

?- write_canonical(if x and  z or t then y).
if(then(and(x,or(z,t)),y))

有没有办法生成:

if( conds, then(actions) ).

或更好:

if( conds, (actions) ).
像这样:

if(x,y)
if(x, then(y))
if( and(x,or(z,t)),  then(y))
if( and(x,or(z,t)),  (y))

我可以看到一种可能的选择:)

?- op(200,  xfy, ==>).

?- write_canonical(x ==> y).
 ==>(x,y)

?- write_canonical(x and z ==> y).
 ==>(and(x,z),y)

1 个答案:

答案 0 :(得分:0)

我找到了更好的解决方案来生成正常的子句。而不是"那么"我可以使用": - "

?- write_canonical(if x and z :- y ).
:-(if(and(x,z)),y)

?- assert(if x and z :- write(axz) ).
?- if x and z.
axz