Flatten 4

Description

Flattening a list of lists using difference-lists

Source: The Art of Prolog

Download

Program source code: flatten_4.pl

Listing

/*	
   flatten(Xs,Ys) :-
	Ys is a flattened list containing the elements in Xs.
*/
	:- op(40,xfx,\).
 
	flatten(Xs,Ys) :- flatten_dl(Xs,Ys\[]).
 
	flatten_dl([X|Xs],Ys\Zs) :-
	   flatten_dl(X,Ys\Ys1), flatten_dl(Xs,Ys1\Zs).
	flatten_dl(X,[X|Xs]\Xs) :-
	   constant(X), X \== [].
	flatten_dl([],Xs\Xs).
 
%	Program 15.2 : Flattening a list of lists using difference-lists

Comments

pl/prolog/pllib/flatten_4.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