如何在文件中使用op / 3

问题描述 投票:2回答:1

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

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

op(35, xfx, is_in).

但是当我consult/1文件在repl中时,我得到一个例外

No permission to modify static procedure `op/3'

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

在repl工作中执行op(35, xfx, is_in).

prolog swi-prolog
1个回答
4
投票

问题是你试图重新定义op/3谓词而不是声明一个新的运算符。

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

:-op(35, xfx, is_in).

请注意,操作符在指令之前不可用,因此您应该在文件中添加高于其用法的指令。

© www.soinside.com 2019 - 2024. All rights reserved.