Controlling parenthesis while working with operators

孤人 提交于 2021-02-11 15:16:18

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/15175400/controlling-parenthesis-while-working-with-operators

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!