3
votes

I'm using SWI-Prolog version 7.6.4 on Arch Linux.

I have this database of facts:

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).

And I defined the mother predicate as follows:

mother(M, C) :- parent(M, C), female(M).

The predicate works as intended:

?- mother(liz, tom).
true .

?- mother(liz, fred).
false.

Now I like to define an operator to be used like liz mother tom with a relatively low precedence, which I do like this:

op(1111, xfx, mother).

This gives me an error on that exact line:

ERROR: /home/user/prolog/family.pl:13:
       No permission to modify static procedure `op/3'

I have no idea what I am doing wrong.

As requested, here's the full file in one listing:

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).
1
Can you share the full file (or at least parts of the file that trigger this exception?). Perhaps the order, spacing, etc. causes this. - Willem Van Onsem
@WillemVanOnsem sure, see above - Patrick Bucher
op/3 is a directive. Did you write :- in front of it? :- op(1111, xfx, mother). The SWI Prolog documentation, unfortunately, is not clear on this point. - lurker
Avoid such operators, they will only hinder you learning the language - false
@false I'll take that advice with me for my further journey, but as you could imagine, this is homework, and the professor wants me to do that. - Patrick Bucher

1 Answers

3
votes

As @lurker described it in the comments, op/3 is a directive. It works like this:

:- op(1111, xfx, mother).