Tuesday, 27 May 2014

Prolog Program to delete all the occurrences of an element from the List.

Prolog Program to delete all the occurrences of an element from the List.

Program:

domains
list=symbol*

predicates
deleteall(symbol,list,list)

clauses
deleteall(_,[],[]).
deleteall(X,[X|T],NT):-deleteall(X,T,NT).
deleteall(X,[H|T],[H|NT]):-H<>X,deleteall(X,T,NT).

goal with output

goal: deleteall(b,[a,b,c,a,b],X)
output: X=["a","c","a"]
           1 solution


No comments:

Post a Comment