next up previous
Next: Unification Up: Prolog Terms Previous: Lists

Operators

Operators in Prolog are simply a notational convenience. We could represent the English statement ``2 plus 3'' in Prolog as +(2, 3) but this isn't the way we are accustomed to seeing the expression. A more familiar notation involves making the + an INFIX operator so that we can write 2 + 3. When an operator is defined it is also allocated two descriptive attributes:

You can check what the current operators in your Prolog system are by using the current_op/3 built-in predicate. You can also define your own operators using the built--in op/3 predicate but we won't worry about this yet. To display a term containing operators in standard Prolog syntax, use the built-in predicate display/1.

| ?- current_op(Precedence, Type, +).

     Precedence=500
     Type=fx ;

     Precedence=500
     Type=yfx 
yes
| ?- current_op(Precedence, Type, *).

     Precedence=400
     Type=yfx
yes
| ?- display(2 + 3 + 4).
+(+(2,3),4)
yes



next up previous
Next: Unification Up: Prolog Terms Previous: Lists



Dave Stuart Robertson
Tue Jul 7 10:44:26 BST 1998