Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filter(A, B)
- filterList(A, [X, Y, Z])
- filter(_,[],[]).
- filter(P, A0-As0, As) :-
- (
- call(P, A0) -> As = A0-As1
- ;
- As = As1
- )
- , filter(P, As0, As1).
- are_identical(X, Y) :-
- X == Y.
- filterList(A, In, Out) :-
- exclude(are_identical(A), In, Out).
- ?- filterList(A, [A, B, A, C, D, A], Out).
- Out = [B, C, D].
- filterList(_, [], R, R). //Returns answer when the list is exhausted.
- filterList(L, [A|List], Temp, Res) :-
- filterList(L, List, New, Res), //Recursive call, New is either the same list
- (filter(L, A), New = Temp; //in case the filter outputs true, or the list
- New = [A|Temp]). //plus the current element otherwise.
Add Comment
Please, Sign In to add comment