如何在文件中使用 op/3

Nik*_*rin 2 prolog

我尝试使用 . 在文件中定义运算符op/3。像这样

is_in(Thing, Place):-
  location(Thing, Place).

op(35, xfx, is_in).
Run Code Online (Sandbox Code Playgroud)

但是当我consult/1提交 repl 时,出现异常

No permission to modify static procedure `op/3'
Run Code Online (Sandbox Code Playgroud)

我尝试使用dynamic指令,但它会导致相同的错误。

在 repl 中执行op(35, xfx, is_in).有效。

gus*_*bro 5

问题是您正在尝试重新定义op/3谓词而不是声明新的运算符。

要在查阅文件时声明新运算符,您必须在程序中添加指令:

:-op(35, xfx, is_in).
Run Code Online (Sandbox Code Playgroud)

请注意,运算符在指令之前不可用,因此您应该在文件中将指令添加到其用法之上。