以下示例是关于Prolog中包含从列表中删除元素用法的示例代码,想了解从列表中删除元素的具体用法?从列表中删除元素怎么用?从列表中删除元素使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。
% output empty list if an element is to be deleted from an empty list
delete_all(_,[],[]).
% if current list head = element, call same predicate without list head to loop
% through input list and don't update output list.
delete_all(X,[X|L],L1):-
delete_all(X,L,L1).
% if current list head != element, call same predicate without list head to loop
% through input list and make head of output list = head of input list.
delete_all(X,[H|L],[H|L1]):-
X\=H,
delete_all(X,L,L1).
本文地址:https://www.itbaoku.cn/snippets/876583.html