operators.pl -- Manage operators
Often, one wants to define operators to improve the readibility of some very specific code. Operators in Prolog are global objects and changing operators changes syntax and possible semantics of existing sources. For this reason it is desirable to reset operator declarations after the code that needs them has been read. This module defines a rather cruel -but portable- method to do this.
Usage:
:- push_operators( [ op(900, fx, hello_world) , op(600, xf, *) ]). hello_world World :- .... :- pop_operators.
While the above are for source-code, the calls push_operators/2 and pop_operators/1 can be used for local processing where it is more comfortable to carry the undo context around.
NOTE: In recent versions of SWI-Prolog operators are local to a module and can be exported using the syntax below. This is not portable, but otherwise a more structured approach for operator handling.
:- module(mymodule, [ mypred/1, op(500, fx, myop) ]).
- push_operators(:New) is det
- push_operators(:New, -Undo) is det
- Installs the operators from New, where New is a list of op(Prec, Type, :Name). The modifications to the operator table are undone in a matching call to pop_operators/0.
- push_op(+Precedence, +Type, :Name) is det
- As op/3, but this call must appear between push_operators/1 and pop_operators/0. The change is undone by the call to pop_operators/0
- pop_operators is det
- Revert all changes to the operator table realised since the last push_operators/1.
- pop_operators(+Undo) is det
- Reset operators as pushed by push_operators/2.
- push_operators(:New) is det
- push_operators(:New, -Undo) is det
- Installs the operators from New, where New is a list of op(Prec, Type, :Name). The modifications to the operator table are undone in a matching call to pop_operators/0.