Esta página le interesa al Wikiproyecto Informática.

elimina

editar

Dear All,

The following:

elimina(X,[X|T],T):- !.
elimina(X,[H|T],[H|T1]):- elimina(X,T,T1).

is better without cut. Since it is offten used:

?- elimina(X,[1,2,3],Y).
X = 1 ;
No   <<< wrong

See also: http://www.complang.tuwien.ac.at/ulrich/iso-prolog/prologue

The predicate there is:

select(X, Xs, Ys) is true if X is an element of the list Xs and Ys is the list Xs with one occurrence of X removed.

Procedurally, select/3 is defined with the following clauses.

select(E, [E|Xs], Xs).
select(E, [X|Xs], [X|Ys]) :- select(E, Xs, Ys).
Volver a la página «Prolog».