1:- module(bc_list, [ 2 take_prefix/3 % +Length, +List, -Prefix 3]). 4 5% Helper to take N first elements 6% from the given list. 7 8take_prefix(N, List, Prefix):- 9 must_be(integer, N), 10 must_be(list, List), 11 take(N, List, Prefix). 12 13take(N, List, Prefix):- 14 ( N =< 0 15 -> Prefix = [] 16 ; N1 is N - 1, 17 ( List = [Head|Tail] 18 -> Prefix = [Head|Rest], 19 take(N1, Tail, Rest) 20 ; Prefix = []))