Defining operators

Author(s): Daniel Cabeza (modifications and documentation, adapted from SICStus 0.6 code), Manuel Carro (modifications and documentation).

Operators allow writing terms in a more clear way than the standard functional notation. Standard operators in Ciao are defined by this predicate (but note that the compiler itself defines more operators at compile time):

standard_ops :-
        op(1200,xfx,[:-]),
        op(1200,fx,[:-,?-]),
        op(1100,xfy,[;]),
        op(1050,xfy,[->]),
        op(1000,xfy,[',']),
        op(900,fy,[\+]),
        op(700,xfx,[=,\=,==,\==,@<,@>,@=<,@>=,=..,is,=:=,=\=,<,=<,>,>=]),
        op(550,xfx,[:]),
        op(500,yfx,[+,-,/\,\/,#]),
        op(500,fy,[++,--]),
        op(400,yfx,[*,/,//,rem,mod,<<,>>]),
        op(200,fy,[+,-,\]),
        op(200,xfx,[**]),
        op(200,xfy,[^]).

Usage and interface

Documentation on exports

PREDICATE
op(Precedence,Type,Name)

Declares the atom Name to be an operator of the stated Type and Precedence (0 =< Precedence =< 1200). Name may also be a list of atoms in which case all of them are declared to be operators. If Precedence is 0 then the operator properties of Name (if any) are cancelled. Note that, unlike in ISO-Prolog, it is allowed to define two operators with the same name, one infix and the other postfix.

Usage:ISO

  • The following properties should hold at call time:
    (basic_props:int/1)Precedence is an integer.
    (basic_props:operator_specifier/1)Type specifies the type and associativity of an operator.
    (basic_props:atm_or_atm_list/1)Name is an atom or a list of atoms.
  • The following properties should hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATE
current_op(Precedence,Type,Op)

The atom Op is currently an operator of type Type and precedence Precedence. Neither Op nor the other arguments need be instantiated at the time of the call; i.e., this predicate can be used to generate as well as to test.

Usage:ISO

  • Call and exit should be compatible with:
    (basic_props:int/1)Precedence is an integer.
    (basic_props:operator_specifier/1)Type specifies the type and associativity of an operator.
    (basic_props:atm/1)Op is an atom.
  • The following properties should hold upon exit:
    (basic_props:int/1)Precedence is an integer.
    (basic_props:operator_specifier/1)Type specifies the type and associativity of an operator.
    (basic_props:atm/1)Op is an atom.
  • The following properties should hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATE
current_prefixop(Op,Less,Precedence)

Similar to current_op/3, but it concerns only the prefix operators. It returns only one solution. Not a predicate for general use.

Usage:

  • Call and exit should be compatible with:
    (basic_props:atm/1)Op is an atom.
    (basic_props:int/1)Less is an integer.
    (basic_props:int/1)Precedence is an integer.
  • The following properties should hold upon exit:
    (basic_props:atm/1)Op is an atom.
    (basic_props:int/1)Less is an integer.
    (basic_props:int/1)Precedence is an integer.
  • The following properties should hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATE
current_infixop(Op,LeftLess,Prec,RightLess)

Similar to current_op/3, but it concerns only infix operators. It returns only one solution. Not a predicate for general use.

Usage:

  • Call and exit should be compatible with:
    (basic_props:atm/1)Op is an atom.
    (basic_props:int/1)LeftLess is an integer.
    (basic_props:int/1)Prec is an integer.
    (basic_props:int/1)RightLess is an integer.
  • The following properties should hold upon exit:
    (basic_props:atm/1)Op is an atom.
    (basic_props:int/1)LeftLess is an integer.
    (basic_props:int/1)Prec is an integer.
    (basic_props:int/1)RightLess is an integer.
  • The following properties should hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATE
current_postfixop(Op,Less,Precedence)

Similar to current_op/3, but it concerns only the postfix operators. It returns only one solution. Not a predicate for general use.

Usage:

  • Call and exit should be compatible with:
    (basic_props:atm/1)Op is an atom.
    (basic_props:int/1)Less is an integer.
    (basic_props:int/1)Precedence is an integer.
  • The following properties should hold upon exit:
    (basic_props:atm/1)Op is an atom.
    (basic_props:int/1)Less is an integer.
    (basic_props:int/1)Precedence is an integer.
  • The following properties should hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATE
No further documentation available for this predicate.