I don't think the current status of the prolog standard op
scene is necessarily a definitive guide to how to use op. Reduction of each op to these type codes (xf, fx, yfx, etc.) was a brilliant invention, but such an invention is more a product of the zeitgeist than the product of any particular rationale (.i.e. the outcome is not necessarily defined by the intentions of the inventor).
xfy
is an op that has a source on the left and a target on the right.
xfx
is an op that has a source on the left and a source on the right.
yfx
is an op that has a target on the left and a source on the right.
'xfy' is (generally) associated with :
- left-to-right
- top-to-bottom
- domination
- being first
- being declarativ
- being ignorant of the 'yfx'
'xfx' is (generally) associated with:
- judgement of the operands
- comparison of things of equal class
- that's all I have for this weirdo
'yfx' is (generally) associated with:
- right-to-left
- bottom-to-top
- egalitarian
- being last (thus ultimately achieving true domination)
- being procedural
- being tolerant of the shenanigans of the 'xfy'
Note that the following works out because the 'x' and 'y' are partnered throughout :
xfy xfx yfx
but in contrast this does not work out:
yfx xfx xfy
Some examples (untested, just sketches)...
(term_expansion((_a),(true)):-(asserta(_a))) .
(term_expansion((_a | _b),(_b)):-(expand_term(_a,_c),asserta(_c))) .
:-
(op(10'1200,'xfy',':='))
,
(op(10'1200,'xfx',':~'))
,
(op(10'1200,'yfx',':-'))
.
(term_expansion((_a := _b :- _c),(term_expansion(_a,_b):-_c))) .
(term_expansion((_a :~ _b :- _c),(goal_expansion(_a,_b):-_c))) .
(term_expansion((_a := _b1 :~ _b2 :- _c),((_a := _b1 :- _c) | (_a :~ _b2 :- _c)))) .
In that example the :-
is yfx
. The syntax is ___consequent___ :- ___precedent___
; the right is the source aka the domain (thus evaluated first), the left is the target aka the codomain (thus evaluated second).
In that example the :~
is xfx
. The syntax is ___goal_1___ :~ ___goal_2__
. It corresponds to a goal_expansion.
In that example the :=
is xfy
. The syntax is ___precedent___ := ___consequence__
. It corresponds to a term_expansion.
:-
(op(10'700,'xfy','@='))
,
(op(10'700,'xfx','\\='))
,
(op(10'700,'yfx','#='))
.
(_x @= _y) :- ('='(_x,_y)) . % .i.e. term equality
% (_x1 \= _x2) % prolog builtin, not equal
% (_y #= _x) % via clpfd, math is generally simplification/\answer is left
The \=
is, in my opinion, the definitiv example of an xfx
operator.
The terminology source | domain, target | codomain
, is from here : https://en.wikipedia.org/wiki/Morphism#Definition.
I don't know much about category theory (yet), but I do wonder if the xfx
has something to do with the identity morphism
.