I suggested the following clpfd-based code for the recent Prolog List Separation question :
list_evens_odds([],[],[]).
list_evens_odds([X|Xs],[X|Es],Os) :-
X mod 2
list_evens_odds(Xs,Es,Os).
list_evens_odds([X|Xs],Es,[X|Os]) :-
X mod 2
list_evens_odds(Xs,Es,Os).
It is concise and clean, but can leave many unnecessary points of choice. Consider:
?- list_evens_odds([1,2,3,4,5,6,7],Es,Os).
The above query reserves a useless selection point for each odd item in [1,2,3,4,5,6,7].
Alternative implementation
Using the reification method demonstrated by @false in Prolog Aggregation for AUBUC can reduce the number of unnecessary selection points. Implementation may change to:
list_evens_odds([],[],[]).
list_evens_odds([X|Xs],Es,Os) :-
if_(#<=>(X mod 2 #= 0), (Es=[X|Es0],Os= Os0),
(Es= Es0, Os=[X|Os0])),
list_evens_odds(Xs,Es0,Os0).
For direct interaction with clpfd-reification, the implementation if_/3can be adapted as follows:
if_( C_1, Then_0, Else_0) :-
call(C_1,Truth01),
indomain(Truth01),
( Truth01 == 1 -> Then_0 ; Truth01 == 0, Else_0 ).
Of course, (=)/3it will also be necessary to adapt to this agreement.
Bottom row
: 0 1 false true ?
? ! !