Reputation: 115
When working with user-defined operators, Prolog sometimes adds / removes parenthesis to expressions involving those operators automatically. Is there a way to control this?
Many thanks
Upvotes: 0
Views: 482
Reputation: 2162
The parens are just added by portray. They're not part of the internal representation of the code. You can override portray to change how things are printed. see portray_text
Upvotes: 3
Reputation: 22803
An operator is defined like so:
:- op(Precedence, Associativity, Operator).
This answer to a similar question explains this, but the short answer is that the Associativity
option controls this; xfy
makes an operator left-associative and yfx
makes an operator right associative. The Precedence
tells Prolog how to decide which operator is the subexpression when it sees more than one.
Upvotes: 1