i'm having difficulty assignment, have write 2 predicates:
remove_all/3
removes instances of given element out of list , output list without given variable, e.g.:
remove_all(a, [b,a,c,a,d], x)
gives
x = [b,c,d])
and
remove_list/3
removes elements of given list out of list , outputs resulting list, e.g.:
remove_list([a,b], [b,a,c,a,d], x)
gives
x=[c,d].
this have:
remove_all(rema,[],[]). remove_all(rema,[rema|x],res) :- remove_all(rema,x,res). remove_all(rema,[l|p],res) :- remove_all(rema,p,nr), res=[l|nr]. remove_list([],listb, listres). remove_list([h|taila],listb,listres) :- member(h,listb), remove_all(h,listb,listres), remove_list(taila,listres,listres) . remove_list([s|tailb],listb,listres) :- remove_list(tailb, listb, listres).
now, remove_all
works fine, not when use in remove_list
predicate, remove instances of first element of list specifies element removed, example:
?- remove_list([1,2],[1,2,3,2,1],f). f = [2, 3, 2]
it removes 1's.
anybody have idea do?
Comments
Post a Comment