Up Next

14.1  What is a Constraint in Logic Programming?

Constraints fit very naturally into the Logic Programming paradigm. Declaratively, a constraint is just the same as any other predicate. Indeed, in ECLiPSe, “constraints” are not a particular programming language construct, constraints are just a conceptual notion.

Consider the following standard Prolog query:

?- member(X, [5,7,3,4]), X =< 4.
This will succeed with X = 3 after some search. In this example, both the member/2 goal and the inequality goal could be considered `constraints on X' because they both restrict the possible values for X. Usually, however, member/2 would not be considered a “constraint” because of its backtracking (search) behaviour:

?- member(X, [5, 7, 3, 4]).
X = 5
More (0.00s cpu)
X = 7
More (0.04s cpu)
Also, the standard Prolog inequality would not be considered a “constraint”, because if invoked on its own it will raise an error:

?- X =< 4.
instantiation fault in X =< 4
In the following, we will call a predicate a constraint only if it
Up Next