devoured elysium
devoured elysium

Reputation: 105047

Problem when trying to define an operator in Prolog

I have defined a prolog file with the following code:

divisible(X, Y) :-
    X mod Y =:= 0.

divisibleBy(X, Y) :-
    divisible(X, Y).

op(35,xfx,divisibleBy).

Prolog is complaining that

'$record_clause'/2: No permission to modify static_procedure `op/3'

What am I doing wrong? I want to define an divisibleBy operator that will allow me to write code like the following:

4 divisibleBy 2

Thanks.

Upvotes: 7

Views: 3012

Answers (2)

repeat
repeat

Reputation: 18726

The answer given by @larsmans is spot-on regarding your original problem.

However, you should reconsider if you should define a new operator.

In general, I would strongly advise against defining new operators for the following reasons:

  • The gain in readability is often overrated.
  • It may easily introduce new problems in places you wouldn't normally expect buggy.
  • It doesn't "scale" well: a small number of operators can make code on presentation slides super-concise, but what if you add more discriminate union cases over time? More operators?

Upvotes: 2

Fred Foo
Fred Foo

Reputation: 363537

Use

:- op(35,xfx,divisibleBy).

:- tells the Prolog interpreter to evaluate the next term while loading the file, i.e. make a predicate call, instead of treating it as a definition (in this case a redefinition of op/3).

Upvotes: 14

Related Questions