Search code examples
prologoperatorsredefineiso-prolog

Prolog reassigning operators


I'm new to prolog and I'm trying to reassign operators in prolog by changing their precedence. I'm running into 4 errors for the following:

 :-op(1000,yf,+).  %unary plus%
 :-op(1000,yf,-).   %unary minus%
 :-op(750,yfx,"%").   %modulo%

The first two give me a similar error that goes like this:

warning: directive failed (op(1000,xf,+)) with exception (error(permission_error(create,operator,+),op/3))

I also get an error with the modulo one (a different error), but I suspect it's because I'm not supposed to enclose % in quotes (but how am I supposed to differentiate it from a comment marker?).

I've redefined a bunch of other operators (such as the addition operator :-op(500,yfx,+).) and they give me no problems. Only the 3 listed above give me errors.

Can anyone shed some light on this?

Thanks!


Solution

  • GNU Prolog documentation states that

    An atom can have multiple operator definitions (e.g. prefix and infix like +) however an atom cannot have both an infix and a postfix operator definitions.

    from here the errors on first two declaration. Then you should change the specifier to fy. The modulo operator will need single quotes around.