Delete element

Description

Deleting all occurrences of an element from a list.

Source: The Art of Prolog

Download

Program source code: delete_element.pl

Listing

/*
	delete(List,X,HasNoXs) :-
		The list HasNoXs is the result of removing all
		occurrences of X from the list List.
*/
 
	delete([X|Xs],X,Ys) :- delete(Xs,X,Ys).
	delete([X|Xs],Z,[X|Ys]) :- X \== Z, delete(Xs,Z,Ys).
	delete([],X,[]).
 
%	Program 3.18: Deleting all occurrences of an element from a list

Comments

pl/prolog/pllib/delete_element.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0