next up previous contents
Next: How to Change Up: Operators Previous: Postfix Operators

How to Find Operator Definitions

It is possible to find out the associativity and precedence of any operator ---whether it is a built-in one or a user-defined one--- with the help of current_op/3. For example, here is how to find out about +:

?- current_op(X,Y,+).


Y=fx ;



produces two solutions (if we ask for a further solution after the first one is found). The first solution is the precedence and associativity for unary + (in that order) and the second is for binary +. Note that you can get all the operators currently known with the help of a failure-driven loop:
?- current_op(X,Y,Z),write_op(X,Y,Z),fail.


write('Operator '),write(Operator),

write(' has precedence '),write(Precedence),

write(' and associativity '),write(Associativity),


You will find some strange things amongst the 45 different operator declarations.

Paul Brna
Mon May 24 20:14:48 BST 1999