The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Message from discussion CHR(FD) syntax standard

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Feb 19 2012, 9:43 am
Newsgroups: comp.lang.prolog
From: Michael Moeller <m...@t-online.de>
Date: Sun, 19 Feb 2012 14:43:54 +0000
Local: Sun, Feb 19 2012 9:43 am
Subject: Re: CHR(FD) syntax standard

On Wed, 8 Feb 2012, A. K. wrote:
> Dear all

> I wonder what would be the standard (or at least most widely used) syntax for
> CHR programming?

> I installed BProlog, Yap and ECLiPSe on Win7. All claim to have CHR solvers.
> From Wikipedia I copied (http://en.wikipedia.org/wiki/Constraint_programming)

> sendmore(Digits) :-
>   Digits = [S,E,N,D,M,O,R,Y],     % Create variables
>   Digits :: [0..9],               % Associate domains to variables
>   S #\= 0,                        % Constraint: S must be different from 0
>   M #\= 0,
>   alldifferent(Digits),           % all the elements must take different
> values
>                1000*S + 100*E + 10*N + D     % Other constraints
>              + 1000*M + 100*O + 10*R + E
>   #= 10000*M + 1000*O + 100*N + 10*E + Y,
>   labeling(Digits).               % Start the search

> but it runs only with BProlog. Why?

> I am not familiar with modern Prolog dialects (having only programmed in
> Turbo Prolog in the pre-Windoze era) but at least I managed to smith together
> in record time a small Sudoku solver in BProlog. :-) But before I continue
> with my experiments, I want to know which system is ideal for learning, and
> which one is 'exotic'.

> Thanks to all who provide their great works and ideas in logic programming
> to simple humans like me!  :-)

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