SWI Prolog:无法定义新运算符
SWI Prolog: Cannot Define New Operator
我在 Arch 上使用 SWI-Prolog 版本 7.6.4 Linux。
我有这个事实数据库:
female(mary). female(liz). female(mia). female(tina). female(ann). female(sue).
male(mike). male(jack). male(fred). male(tom). male(joe). male(jim).
parent(mary, mia). parent(mary, fred). parent(mary, tina).
parent(mike, mia). parent(mike, fred). parent(mike, tina).
parent(liz, tom). parent(liz, joe).
parent(jack, tom). parent(jack, joe).
parent(mia, ann).
parent(tina, sue). parent(tina, jim).
parent(tom, sue). parent(tom, jim).
并且我定义了 mother
谓词如下:
mother(M, C) :- parent(M, C), female(M).
谓词按预期工作:
?- mother(liz, tom).
true .
?- mother(liz, fred).
false.
现在我想定义一个像 liz mother tom
这样优先级相对较低的运算符,我喜欢这样:
op(1111, xfx, mother).
这在确切的行上给我一个错误:
ERROR: /home/user/prolog/family.pl:13:
No permission to modify static procedure `op/3'
我不知道我做错了什么。
根据要求,这是一个列表中的完整文件:
female(mary). female(liz). female(mia). female(tina). female(ann). female(sue).
male(mike). male(jack). male(fred). male(tom). male(joe). male(jim).
parent(mary, mia). parent(mary, fred). parent(mary, tina).
parent(mike, mia). parent(mike, fred). parent(mike, tina).
parent(liz, tom). parent(liz, joe).
parent(jack, tom). parent(jack, joe).
parent(mia, ann).
parent(tina, sue). parent(tina, jim).
parent(tom, sue). parent(tom, jim).
mother(M, C) :- parent(M, C), female(M).
op(1111, xfx, mother).
正如@lurker 在评论中所描述的那样,op/3
是一个指令。它是这样工作的:
:- op(1111, xfx, mother).
我在 Arch 上使用 SWI-Prolog 版本 7.6.4 Linux。
我有这个事实数据库:
female(mary). female(liz). female(mia). female(tina). female(ann). female(sue).
male(mike). male(jack). male(fred). male(tom). male(joe). male(jim).
parent(mary, mia). parent(mary, fred). parent(mary, tina).
parent(mike, mia). parent(mike, fred). parent(mike, tina).
parent(liz, tom). parent(liz, joe).
parent(jack, tom). parent(jack, joe).
parent(mia, ann).
parent(tina, sue). parent(tina, jim).
parent(tom, sue). parent(tom, jim).
并且我定义了 mother
谓词如下:
mother(M, C) :- parent(M, C), female(M).
谓词按预期工作:
?- mother(liz, tom).
true .
?- mother(liz, fred).
false.
现在我想定义一个像 liz mother tom
这样优先级相对较低的运算符,我喜欢这样:
op(1111, xfx, mother).
这在确切的行上给我一个错误:
ERROR: /home/user/prolog/family.pl:13:
No permission to modify static procedure `op/3'
我不知道我做错了什么。
根据要求,这是一个列表中的完整文件:
female(mary). female(liz). female(mia). female(tina). female(ann). female(sue).
male(mike). male(jack). male(fred). male(tom). male(joe). male(jim).
parent(mary, mia). parent(mary, fred). parent(mary, tina).
parent(mike, mia). parent(mike, fred). parent(mike, tina).
parent(liz, tom). parent(liz, joe).
parent(jack, tom). parent(jack, joe).
parent(mia, ann).
parent(tina, sue). parent(tina, jim).
parent(tom, sue). parent(tom, jim).
mother(M, C) :- parent(M, C), female(M).
op(1111, xfx, mother).
正如@lurker 在评论中所描述的那样,op/3
是一个指令。它是这样工作的:
:- op(1111, xfx, mother).