I'm working on an exercise whereby I'm trying to use the =.. predicate to write a procedure that removes all elements in List for which PredName(X) fails and returns the remaining list as Result:
filter(List, PredName, Result)
In this case with PredName being defined as:
test(N) :- atom(N).
For example:
?- filter([a,b,-6,7,A,-1,0,B], test, L).
L = [a,b,-6,7,-1,0],
I've got the following, but I'm not sure why I keep getting false as a result when testing with the example above:
test(N):-
atomic(N).
filter([], _, []).
filter2([H|T], PredName, [H|S]):-
Goal =.. [PredName, H],Goal,filter(T, PredName, S),!.
filter([H|T], PredName, S) :-
filter2(T, PredName, S).
I got the above code from here.