Syntax varies depending on the Prolog you use. The example is clp(FD).
GNU-Prolog, BProlog and ECLiPSe used to implement CLP(FD),
Yap CHR and CLP(R) and XSB CHR. SWI has CHR, CLP(FD) and CLP(R, Q).
In gprolog the example will be something like this (taken from the gprolog
distribution):
sendmoremoney(Vars) :-
Vars = [S,E,N,D,M,O,R,Y],
fd_domain(Vars, 0, 9),
S #\= 0,
M #\= 0,
fd_all_different(Vars),
1000*S + 100*E + 10*N + D
+ 1000*M + 100*O + 10*R + E
#= 10000*M + 1000*O + 100*N + 10*E + Y.
send :- Vars=[S,E,N,D,M,O,R,Y], sendmoremoney(Vars), fd_labeling(Vars),
write(Vars), nl.
q :- statistics(runtime,_), send,
statistics(runtime,[_,Y]),
write('time : '), write(Y), nl.
:- initialization(q).
CHR in Yap is like this (just to give you an impression)
% Sieve of Erathostenes (Constraint Handling Rules, Holzbaur/Fruehwirth)
:- use_module(library(chr)).
handler erathostenes.
constraints primes/1, prime/1.
primes(1) <=> true.
primes(N) <=> N > 1 | M is N - 1, prime(N), primes(M).
absorb(J) @ prime(I) \ prime(J) <=> J mod I =:= 0 | true.
Most Prologs come with some examples. In addition lots of
documents are freely available on the internet.
Regards,
Michael