diff --git a/docs/yap.tex b/docs/yap.tex index 606b72ad8..05343a0cd 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -7217,9 +7217,9 @@ Holds when @code{append(_,Suffix,List)} holds. @item sum_list(?@var{Numbers}, ?@var{Total}) @findex sum_list/2 -@snindex sum_list/2 +@syindex sum_list/2 @cnindex sum_list/2 -True when @var{Numbers} is a list of integers, and @var{Total} is their sum. +True when @var{Numbers} is a list of numbers, and @var{Total} is their sum. @item sumlist(?@var{Numbers}, ?@var{Total}) @findex sumlist/2 @@ -7229,6 +7229,18 @@ True when @var{Numbers} is a list of integers, and @var{Total} is their sum. The same as @code{sum_list/2}, please do use @code{sum_list/2} instead. +@item max_list(?@var{Numbers}, ?@var{Max}) +@findex max_list/2 +@syindex max_list/2 +@cnindex max_list/2 +True when @var{Numbers} is a list of numbers, and @var{Max} is the maximum. + +@item min_list(?@var{Numbers}, ?@var{Min}) +@findex min_list/2 +@syindex min_list/2 +@cnindex min_list/2 +True when @var{Numbers} is a list of numbers, and @var{Min} is the minimum. + @end table @node Ordered Sets, Pseudo Random, Lists, Library diff --git a/library/lists.yap b/library/lists.yap index dcf3b4562..9aee2e1c6 100644 --- a/library/lists.yap +++ b/library/lists.yap @@ -26,8 +26,10 @@ suffix/2, sumlist/2, list_concat/2, - flatten/2 - ]). + flatten/2, + max_list/2, + min_list/2 + ]). % append(Prefix, Suffix, Combined) @@ -331,3 +333,29 @@ flatten_list([]) --> !. flatten_list([H|T]) --> !, flatten_list(H),flatten_list(T). flatten_list(H) --> [H]. +max_list([H|L],Max) :- + max_list(L,H,Max). + +max_list([],Max,Max). +max_list([H|L],Max0,Max) :- + ( + H > Max0 + -> + max_list(L,H,Max) + ; + max_list(L,Max0,Max) + ). + +min_list([H|L],Max) :- + max_list(L,H,Max). + +min_list([],Max,Max). +min_list([H|L],Max0,Max) :- + ( + H < Max0 + -> + max_list(L, H, Max) + ; + max_list(L, Max0, Max) + ). + diff --git a/pl/yio.yap b/pl/yio.yap index 43b99c330..e2889e3cb 100644 --- a/pl/yio.yap +++ b/pl/yio.yap @@ -873,6 +873,16 @@ at_end_of_stream(S) :- '$peek'(S,N), N = -1. +at_end_of_line :- + current_input(S), + at_end_of_line(S). + +at_end_of_line(S) :- + '$past_eof'(S), !. +at_end_of_line(S) :- + '$peek'(S,N), ( N = 10 -> true ; N = -1). + + consult_depth(LV) :- '$show_consult_level'(LV). absolute_file_name(V,Out) :- var(V), !,