更新时间:2023-02-23 10:36:55
对列表执行大多数操作都将需要考虑两种情况:空列表以及带有标题和子列表的列表.通常,您的基本案例处理空列表,而归纳案例处理带有子列表的列表.
Doing most anything with lists will require that you consider two cases: the empty list and a list with a head and a sublist. Usually your base case is handling the empty list and your inductive case is handling the list with sublist.
首先考虑您的基本情况:
First consider your base case:
cons([], null).
现在处理您的归纳案件:
Now deal with your inductive case:
cons([X|Xs], next(X, Rest)) :- cons(Xs, Rest).