Prolog Language Operators Operator declaration

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

In Prolog, custom operators can be defined using op/3:

op(+Precedence, +Type, :Operator)

  • Declares Operator to be an operator of a Type with a Precedence. Operator can also be a list of names in which case all elements of the list are declared to be identical operators.

  • Precedence is an integer between 0 and 1200, where 0 removes the declaration.

  • Type is one of: xf, yf, xfx, xfy, yfx, fy or fx where f indicates the position of the functor and x and y indicate the positions of the arguments. y denotes a term with a precedence lower or equal to the precedence of the functor, whereas x denotes a strictly lower precedence.

    • Prefix: fx , fy
    • Infix: xfx (not associative), xfy (right associative), yfx (left associative)
    • Postfix: xf , yf

Example usage:

:- op(900, xf, is_true).

X_0 is_true :-
  X_0.

Example query:

?- dif(X, a) is_true.
dif(X, a).


Got any Prolog Language Question?