Reputation: 315
I know of the subtract predicate which removes which removes a list of items from a list
subtract([a,b,c,a,b], [a,c], X).
but is there anything like
remove([a,b,c,a,b], a, X).
I know I can modify the above in
subtract([a,b,c,a,b], [a], X).
To achieve the desired result.
But I want to know if there is another way?
EDIT:
@user27815
you did provide a very detailed answer but i'm still very much new to prolog. And perhaps I didn't ask the question correctly(My bad). If there is another way to achieve this.Is it Pre-defined or do I have to define it myself. And can I have an example?
Upvotes: 1
Views: 199
Reputation: 4797
Of course, there are many ways. A good way to do this is to use library reif.
See the answer to this question by repeat:
There are some general use predicates which are defined that you can adapt to your program.
remove(List,Element,NewList):-
tinclude(not(list_memberd_truth([Element])),List,NewList).
Upvotes: 3