Flatten

Description

Flattening a list with double recursion

Source: The Art of Prolog

Download

Program source code: flatten.pl

Listing

/*
   flatten(Xs,Ys) :- Ys is a list of the elements of Xs.
*/
 
    flatten([X|Xs],Ys) :- 
        flatten(X,Ys1), flatten(Xs,Ys2), append(Ys1,Ys2,Ys).
    flatten(X,[X]) :- X \== [].
%	constant(X), X \== [].
    flatten([],[]).
 
 
% Program 9.1a   Flattening a list with double recursion

Comments

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