Hello. Please tell me why the program does not work, I am writing to Prolog 5.2. Condition: Create a predicate that calculates, by list and number, a sublist of the original list, starting with the item with the specified number.

domains list = integer* predicates sublist(integer,integer,list,list) clauses sublist(_,_,[],[]):-!. sublist(N,N,L,L):-!. sublist(M,N,[H|T],T1):- M<N, M1=M+1, sublist(M1,N,T,T1). goal write("N="), readint(N), write("L="), readterm(list,L), sublist(1,N,L,L1),write(L1),nl. 

Error after entering N and L:

 PROGRAM ERROR. Module:OBJ\GOAL$000.PRO Pos:831 Message:1405 List start expected (during term reading or converting) 

Thank you in advance

    1 answer 1

     split(List, Number, Right):- PredNumber is Number - 1, append(Left, Split, List), length(Left, PredNumber). 

    The bottom line is that if you need a part starting from the Nth element of the list, then N-1 elements are located in front of it. Those. you need to divide the initial list into first N-1 elements and the rest. You can divide the list with the embedded predicate append, determine the length - length. If you write on some Turbo Prolog, then there are no such built-in predicates, but you can find them here: article about lists on Prolog