Elena
Elena

Reputation: 31

Delete the first N elements from a list in Prolog

How can I delete the first N elements from a list in Prolog? How can I get the first N elements from a list into another list? I need this in order to insert a list in another list from a specified position. I already have the concatenation function and plan to get a list of the first N elements of the initial list, concatenate it with the second list, then concatenate the result with the list of the remaining elements in the first list (obtained by deleting the first N elements).

Upvotes: 2

Views: 3537

Answers (1)

liori
liori

Reputation: 42267

?- length(X, 3), append(X, Y, [a,b,c,d,e,f,g,h]).
X = [a, b, c],
Y = [d, e, f, g, h].

Upvotes: 13

Related Questions