Reputation: 33
Having defined two operators in Prolog:
op(100, xfy, #).
op(100, fy, ϴ).
what is the expression
a # ϴ b # c
equivalent to?
a # ϴ (b # c)
or maybe
a # ((ϴ b) # c)
And why?
Upvotes: 3
Views: 557
Reputation: 58234
You can see what Prolog will do with it using write_canonical/1
:
?- op(100,xfy,#).
true.
?- op(100,fy,@).
true.
?- write_canonical(a # @ b # c).
#(a,@(#(b,c)))
true.
So, it appears that your first speculation is correct. The interpretation of a # @ b # c
is a # (@(b # c))
. The key comment in the documentation for op/3
bearing on this is:
The
f
indicates the position of the functor, whilex
andy
indicate the position of the arguments.y
should be interpreted as "on this position a term with precedence lower or equal to the precedence of the functor should occur". Forx
the precedence of the argument must be strictly lower.
The use of fy
results in the precedence grouping of @(b # c)
rather than (@b) # c
.
Upvotes: 4