include flatten/2 in library(lists).
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@598 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
d6778dac3a
commit
7076ced716
15
docs/yap.tex
15
docs/yap.tex
@ -6941,6 +6941,21 @@ True when @var{List} is a list, in which @var{Element} may or may not
|
|||||||
occur, and @var{Residue} is a copy of @var{List} with all elements
|
occur, and @var{Residue} is a copy of @var{List} with all elements
|
||||||
identical to @var{Element} deleted.
|
identical to @var{Element} deleted.
|
||||||
|
|
||||||
|
@item flatten(+@var{List}, ?@var{FlattenedList})
|
||||||
|
@findex flatten/2
|
||||||
|
@syindex flatten/2
|
||||||
|
@cnindex flatten/2
|
||||||
|
Flatten a list of lists @var{List} into a single list
|
||||||
|
@var{FlattenedList}.
|
||||||
|
|
||||||
|
@example
|
||||||
|
?- flatten([[1],[2,3],[4,[5,6],7,8]],L).
|
||||||
|
|
||||||
|
L = [1,2,3,4,5,6,7,8] ? ;
|
||||||
|
|
||||||
|
no
|
||||||
|
@end example
|
||||||
|
|
||||||
@item is_list(+@var{List})
|
@item is_list(+@var{List})
|
||||||
@findex is_list/1
|
@findex is_list/1
|
||||||
@syindex is_list/1
|
@syindex is_list/1
|
||||||
|
@ -25,7 +25,8 @@
|
|||||||
sum_list/2,
|
sum_list/2,
|
||||||
suffix/2,
|
suffix/2,
|
||||||
sumlist/2,
|
sumlist/2,
|
||||||
list_concat/2
|
list_concat/2,
|
||||||
|
flatten/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
@ -321,4 +322,12 @@ list_concat([H|T], [H|Lf], Li) :-
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%
|
||||||
|
% flatten a list
|
||||||
|
%
|
||||||
|
flatten(X,Y) :- flatten_list(X,Y,[]).
|
||||||
|
|
||||||
|
flatten_list([]) --> !.
|
||||||
|
flatten_list([H|T]) --> !, flatten_list(H),flatten_list(T).
|
||||||
|
flatten_list(H) --> [H].
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user