1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Sieve of eratosthenes to compute primes
4 %% thom fruehwirth 920218-20, 980311
5 %% christian holzbaur 980207 for Sicstus CHR
7 %% ported to hProlog by Tom Schrijvers
9 :- module(primes,[primes/0]).
10 :- use_module(library(chr)).
12 :- constraints candidate/1.
13 :- constraints prime/1.
14 :- constraints cleanup/1.
16 candidate(1) <=> true.
17 candidate(N) <=> prime(N), N1 is N - 1, candidate(N1).
19 absorb @ prime(Y) \ prime(X) <=> 0 =:= X mod Y | true.
21 cleanup(_L), candidate(_X) <=> fail.
22 cleanup(L), prime(N) <=> L = [N|T], cleanup(T).
23 cleanup(L) <=> L = [].
29 SL == [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97].