I am doing an exercise from 'Prolog Programming for Artificial Intelligence' by Ivan Bratko. The exercise says:
Define the operators 'if', 'then', 'else' and ':=', so that the following becomes a legal term:
if X > Y then Z := X else Z := Y
Choose the precedences so that 'if' will be the principal functor.
I am having trouble determining out of the operators 'then' and 'else', which one should have the lower precedence (and bind stronger). My answer to this question was:
:- op(900, fx, if).
:- op(800, xfx, else).
:- op(700, xfx, then).
:- op(600, xfx, :=).
(It is also stated in the book that the '>' operator has precedence of 700).
I thought that 'then' would bind stronger than 'else', however the answer for this exercise states otherwise:
:- op(900, fx, if).
:- op(800, xfx, then).
:- op(700, xfx, else).
:- op(600, xfx, :=).
I am not sure of the rationale behind making 'else' have lower precedence than 'then'. Any insights are greatly appreciated.