projog

3.104. delete(X,Y,Z) - remove all occurrences of a term from a list.

Removes all occurrences of the term Y in the list represented by X and attempts to unify the result with Z. Strict term equality is used to identify occurrences.

Examples

?- delete([a,b,c],a,X).
X = [b,c]

yes

?- delete([a,a,b,a,b,b,c,b,a],a,X).
X = [b,b,b,c,b]

yes

?- delete([a,b,c],b,X).
X = [a,c]

yes

?- delete([a,b,c],c,X).
X = [a,b]

yes

?- delete([a,b,c],z,X).
X = [a,b,c]

yes

?- delete([],a,X).
X = []

yes

?- delete([a,b,X],a,[Y,c]).
X = c
Y = b

yes

?- delete([a,b,c],Y,X).
X = [a,b,c]
Y = UNINSTANTIATED VARIABLE

yes

?- delete([a,Y,c],b,X).
X = [a,Y,c]
Y = UNINSTANTIATED VARIABLE

yes

?- delete([a,Y,_],_,X).
X = [a,Y,_]
Y = UNINSTANTIATED VARIABLE

yes

?- W=Y,delete([a,Y,_],W,X).
W = UNINSTANTIATED VARIABLE
X = [a,_]
Y = UNINSTANTIATED VARIABLE

yes

?- delete([],a,X).
X = []

yes

Note: unlike SWI Prolog, fails if the first argument is a partial list.

?- delete([a,b,c|X],Y,Z).

no