小编Bud*_*dyW的帖子

无法在prolog中定义中缀二进制运算符

我刚刚开始讲道.我想定义一个中缀二进制运算符"rA",当我给出矩形的宽度和宽度时,它给出了矩形区域.这是我的代码:

:-op(300, xfy, rA).

rA(X,Y,R) :- R is X*Y.
Run Code Online (Sandbox Code Playgroud)

我执行此操作时代码工作正常:

1 ?- rA(3,4,A).
A = 12. 
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚的是将其定义为中缀二元运算符.我收到此错误:

2 ?- A is 3 rA 4.
ERROR: evaluable `3 rA 4' does not exist 
Run Code Online (Sandbox Code Playgroud)

谢谢

operators prolog swi-prolog

5
推荐指数
1
解决办法
646
查看次数

标签 统计

operators ×1

prolog ×1

swi-prolog ×1