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 :- chr_constraint candidate/1.
13 :- chr_constraint prime/1.
14 :- chr_constraint cleanup/1.
16 :- chr_option(debug,off).
17 :- chr_option(optimize,full).
19 candidate(1) <=> true.
20 candidate(N) <=> prime(N), N1 is N - 1, candidate(N1).
22 absorb @ prime(Y) \ prime(X) <=> 0 =:= X mod Y | true.
24 cleanup(_L), candidate(_X) <=> fail.
25 cleanup(L), prime(N) <=> L = [N|T], cleanup(T).
26 cleanup(L) <=> L = [].
32 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].