How to remove negative numbers from a list in Prolog
Posted on 2008-10-07
I'm trying to take a list, and remove only the negative numbers. So far i have this
non_neg([H|T],S) :- H<0, non_neg(T,S).
non_neg([H|T],S) :- H>=0, non_neg(T,H).
I'm pretty sure the error is in the 3rd line because when i query with an empty list or a list consisting of only negaive numbers it works fine. Sorry i'm a noob.