# Careful with op/3

There are always rumors that the ISO core standard syntax
is ambiguous. But its rather the other way around. The ISO
core standard explicitly says its not ambigious:

But the given example is misunderstood as requirement
of a parse that nevertheless needs a lot of lookahead. Why
is this example misunderstood?

Well its an impossible example, so therefore I think its
a negative example and not a positive example. There are no
yf_or_yfx operators in ISO core standard Prolog. Since among the

constraints for multiple operators is the following constraint:

Unfortunately SWI-Prolog doesn’t implement the constraint.

I can do:

``````/* SWI-Prolog (threaded, 64 bits, version 8.5.8) */
?- op(400,yf,f).
true.

?- op(400,yfx,f).
true.
``````

What would be a usecase for such an operator? I
tryed the example from ISO core standard, but it
doesn’t work 100% as is stated in the ISO core standard.

If I use same priority, its not parsable:

``````?- op(400,fy,g).
true.

?- op(400,yf,g).
true.

?- X = r f g s, write_canonical(X).
ERROR: Syntax error: Operator priority clash

?- X = r f g g, write_canonical(X).
ERROR: Syntax error: Operator priority clash
``````

If I use lower priority, it gives a different resulting term:

``````?- op(300,fy,g).
true.

?- op(300,yf,g).
true.

?- X = r f g s, write_canonical(X).
f(r,g(s))
X = r f g s.

?- X = r f g g, write_canonical(X).
f(r,g(g))
X = r f g (g).
``````

Edit 06.04.2022:
I tried a few other Prolog systems, like Tau Prolog and
Scryer Prolog, they all implement the constraint:

``````?- op(400,yf,f).
true.

?- op(400,yfx,f).
caught: error(permission_error(create,operator,f),op/3)
``````

Or maybe the check is more difficult to perform
in a module context? Similar problem like here:

Only with infix and postfix for operators, instead of
static and built_in for predicates.

On the other hand I remember SWI-Prolog being
quite strict about ambiguous import of predicates.

Edit 09.04.2022:
Now I found a test case where SWI-Prolog and
Scryer Prolog differ in parsing:

``````/* SWI-Prolog */
?- op(9,fy,fy), op(9,yfx,yfx).
true.

?- X = (fy 1 yfx 2), write_canonical(X), nl.
yfx(fy(1),2)
``````

But then:

``````/* Scryer Prolog */
?- op(9,fy,fy), op(9,yfx,yfx).
true.

?- X = (fy 1 yfx 2), write_canonical(X), nl.
fy(yfx(1,2))
``````

Was worried what Dogelog Player does. But it seems Dogelog Player
sides with Scryer Prolog, also GNU Prolog, Tau Prolog and
formerly Jekejeke Prolog do.