Operator priority evaluation order in Prolog -
if define operator:
op(700, yfx, sum).
700: rappresent priority respect other operators.
yfx: rappresent precedence of arguments respect operator itself. configuration operator infix , argument y have precedence <= operatore priority , argument x have precedence < of operator priority.
the highest precedence principal functor of therms, means isthe last operation executed..
so, means if have following evalutation:
9 sum 5 sum 7
so means have 3 in first evvaluate value of 5 sum 7 , evaluate: 9 sum (5 sum 7)
is right reasoning operator priority?
i think wording different you're using:
700: precedence. lower binds more strictly.
yfx: associativity left.
?- write_canonical(1 sum 2 sum 3).
yields sum(sum(1,2),3)
.
this operator associate left, arithmetic binary operators:
?- setof(x-o,current_op(x,yfx,o),l),pairs_keys_values(l,_,os). l = [250- (?), 400- (*), 400- (/), 400- (//), 400- (<<), 400- (>>), 400- (div), 400- (mod), ... - ...|...], os = [?, *, /, //, <<, >>, div, mod, rdiv|...].
a practical way inspect operator' relations via unification.
?- (1 sum 2 sum 3) = (1 sum x). false. ?- (1 sum 2 sum 3) = (x sum 3). x = (1 sum 2).
note parenthesis required (sum has higher precedence unification (=)/2).
for predefined, systemic, operators see doc page.
Comments
Post a Comment