Re: negotiation by failure- list operations



all i need is a modified delete1 predicate that throws back a YES if x
isnt in the List. - the point is the yes - not deleting all matching
elements in the list.

its like a if then construction

delete1(x,[L1],Y).
if x isnt in the list - then halt and give back a YES, if x is in the
list- procede with delete

Has nobody an idea ?

Greetings


Brian Hulley schrieb:
> > > % strange version of delete that only deletes
> > > % the first matching element...
> > > delete(E,[E|T],T).
> > > delete(E,[H|T],[H|DT]) :-
> > > delete(E,T,DT).
>
> (The above delete/3 needs a cut as well ie delete(E,[E|T],T) :- !. )
>
> Normal efficient delete that deletes all matching elements and
> therefore always succeeds regardless of E:
>
> delete(_,[],[]).
> delete(E,[E|T],DT) :- !, delete(E,T,DT).
> delete(E,[H|T],[H|DT]) :- delete(E,T,DT).

.



Relevant Pages