Logic Programming

Constraint Logic Programming (CLP)

Constraint Logic Programming is a combination of logic programming and constraint solving, that was introduced in the 1980s. It allows the programs to be expressive and flexible. Programmers are given more control by having constraints for variables in the body of a program. The body of a constraint logic program is evaluated similarly to normal logic programming, however, the constraints which are in the body must be satisfied.

A(X) :- X>0, B(X).

The Statement A(X) only holds when the constraint X>0 is true and B(X) can also be evaluated as true.

Constraints limit the possibilities of a variable as shown in the example where the variable X can only be greater than 0. Unlike primitives of other programming languages which define a sequence of steps for execution, a constraint is a property of a program which must be satisfied. Constraints are placed in a constraint store which the interpreter evaluates. If the constraints in the constraint store are not satisfied the interpreter backtracks and the statement does not hold. The goal must then be proved using other statements within the program.