:- module(ac_list_util, [ list_offset/3, % +List, +N, +SmallerList list_limit/4 % +List, +N, +FirstN, Rest ]). %% list_offset(+List, +N, -SmallerList) % % SmallerList starts at the nth element of List. list_offset(L, N, []) :- length(L, Length), Length < N, !. list_offset(L, N, L1) :- list_offset_(L, N, L1). list_offset_(L, 0, L) :- !. list_offset_([_|T], N, Rest) :- N1 is N-1, list_offset_(T, N1, Rest). %% list_limit(+List, +N, -SmallerList, -Rest) % % SmallerList ends at the nth element of List. list_limit(L, N, L, []) :- N < 0, !. list_limit(L, N, L, []) :- length(L, Length), Length < N, !. list_limit(L, N, L1, Rest) :- list_limit_(L, N, L1, Rest). list_limit_(Rest, 0, [], Rest) :- !. list_limit_([H|T], N, [H|T1], Rest) :- N1 is N-1, list_limit_(T, N1, T1, Rest).