4 ms·
Constraints blend in especially seamlessly with logic programming languages like Prolog. In fact, Prolog itself can be regarded as a constraint solver over Herb
by triska 5y ago
Constraints blend in especially seamlessly with logic programming languages like Prolog. In fact, Prolog itself can be regarded as a constraint solver over Herbrand terms.
For instance, here is the "adder" example from the paper, using Scryer Prolog and its built-in constraint solver over integers:
$ scryer-prolog
?- use_module(library(clpz)).
true.
?- A1 + A2 #= Sum.
clpz:(A1+A2#=Sum).
?- A1 + A2 #= 5.
clpz:(A1+A2#=5).
?- -2 + A2 #= 5.
A2 = 7.
In this interaction, we state what we know about the relation, and the answer tells us what the system has deduced. For example, given the sum and A1, the system has deduced that A2 is 7.
The speed and sophistication of built-in constraint solvers over various domains is often an important reason for buying a commercial Prolog system.