Welcome to W3Courses
 Like Us on Facebook

Delete all occurrences of an Element from a List using Prolog Source Code

The following code deletes all occurrences of an element from a list

CODE
deleteall([],A,[]).
deleteall([H|T],A,Result) :- H=A, deleteall(T,A,Result).
deleteall([H|T],A,[H|Result]) :- deleteall(T,A,Result).


RESULT
?- deleteall([a,b,a,c],a,Result).
Result = [b, c]
Yes


 

Share