像这样定义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)
我找到了更好的解决方案来生成普通子句。代替"然后",我可以只使用":-">
?- write_canonical(if x and z :- y ).
:-(if(and(x,z)),y)
?- assert(if x and z :- write(axz) ).
?- if x and z.
axz