Write a program in prolog to delete all reference of a particular item from a list. It should have three arguments. The list you wish to use, the item to delete, and the resulting list. Here are some example of it behaviour
?- delete_all([a,b,a,c,a,d],a,Result).
Result = [b,c,d]
? - delete_all([a,b,a,c,a,d],b,Result).
Result = [a,a,c,a,d]
delete_all([],_,[]):-!. %If list is empty then
Resultant list is also empty
delete_all([Elem|T],Elem,R):- delete_all(T,Elem,R). %If
Head of the list is same as Element to be deleted, Remove It
delete_all([H|T],Elem,[H|R]):-H \= Elem,
delete_all(T,Elem,R). %move ahead
/* OUTPUT */
/* please upvote */
Get Answers For Free
Most questions answered within 1 hours.