How do I write a procedure in Prolog that clears a list of integers of its negative elements and returns the result in a new list? Without using cuts but can use negation.>
Using recursion for the last case,
I'd write :
filter([],[]). filter([H|T],S) :- H<0, filter(T,S). filter([H|T], L) :- H>=0, filter(T, S), append([H],S,L).