% Since Prova 1.9.
% The example shows how to use a built-in predicate 'sort_list' that sorts
%    a Prova list IN PLACE. The second argument is a Java Comparator.
%    Prova includes one default Comparator for Strings with a singleton instance included in the class.
 
:- eval(ex056()).


ex056() :-
	List = ["4","3",X,"2"],
	X = ["1","2"],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).
ex056() :-
	List = ["4","3",X,"2"],
	TraLaLa = ["1","2"],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).
ex056() :-
	List = ["4","3","1","2"],
	TraLaLa = ["1","2"],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).
ex056() :-
	List = [2,1,a,2],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).
ex056() :-
	List = ['cd','ab','aab','cad'],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).
ex056() :-
	List = [['cd','aab'],'ab',X,'aab','cad'],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).
ex056() :-
	List = [2,1,2,b],
	element(I,["1","2"]),
	ex056_2(List),
	println([List]).
ex056() :-
	List = [2,1,2,c],
	Toto = ["1","2"],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator),
	println([List]).

ex056_2(List) :-
	Toto = ["1","2"],
	sort_list(List,ws.prova.comparators.StringComparator.stringComparator).

% Prints:
%
% [1,2,2,"a"]
% ["aab","ab","cad","cd"]
% ["aab","ab","cad",["cd","aab"],X]
% [1,2,2,"b"]
% [1,2,2,"b"]
% [1,2,2,"c"]
