:- module(primes, [], [assertions, regtypes, nativeprops, predefres(res_steps)]).


:- entry sift/2: list(int) * var.
:- pred sift(Is, Ps) : intlist * term => intlist * intlist.
sift([], []).
sift([I | Is], [I | Ps]) :-
        remove(Is, I, New),
        sift(New, Ps).


:- pred remove(Is, P, Ps) : intlist * int * var => intlist * int * intlist.
remove([], _, []).
remove([I | Is], P, Nis) :-
        IModP is I mod P,
        IModP = 0, !,
        remove(Is, P, Nis).
remove([I | Is], P, [I | Nis]) :-
        remove(Is, P, Nis).

:- regtype intlist/1.
intlist([]).
intlist([X|Xs]) :-
    int(X),
    intlist(Xs).