简体   繁体   English

从Prolog中的列表中删除前N个元素

[英]Delete the first N elements from a list in Prolog

How can I delete the first N elements from a list in Prolog? 如何从Prolog中的列表中删除前N个元素? How can I get the first N elements from a list into another list? 如何将列表中的前N个元素转换为另一个列表? 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). 我已经有了连接函数,并计划获取初始列表的前N个元素的列表,将其与第二个列表连接,然后将结果与第一个列表中剩余元素的列表连接起来(通过删除第一个N个元素)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM