Prolog lists of ascending number inside a list
问题 I Have a list of [1,2,3,1,0] at start but need to split it into a number of sub lists where the new lists becomes [[1,2,3],[1],[0]]. The basic concept that I know in prolog is by comparing numbers. ascending([Head | [HeadTail|TailTail]]) :- Head =< HeadTail. 回答1: we can do with basic list' pattern matching ascending([A], [[A]]). ascending([A,B|T], R) :- ( A > B -> R = [[A],P|Q] ; P = [M|N], R = [[A,M|N]|Q] ), ascending([B|T], [P|Q]). test: 1 ?- ascending([1,2],X). X = [[1, 2]] ; false. 2 ?-