本文介绍了序言删除:不会删除所有与Element合并的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SWI-Prolog的delete/3谓词有疑问.最简单的方法只是一个简单的例子:

I'm having an issue with SWI-Prolog's delete/3 predicate.The easiest way is just a quick example:

?- delete([(1,1),(1,2),(3,2)], (1,_), List).
List = [(1,2),(3,2)].

我希望(1,2)也将被删除,因为(1,_)(1,2)统一. SWIPL帮助说:

I would expect (1,2) to also be deleted, since (1,_) unifies with (1,2). The SWIPL help says:

这是为什么?如何删除与(1,_)统一的所有内容?

Why is this and how can I delete everything that unifies with (1,_)?

推荐答案

删除同时与Elem统一的List1的所有成员,并与List2统一结果."

" Delete all members of List1 that simultaneously unify with Elem and unify the result with List2."

(1,X)首先与(1,1)统一.因此,X与1统一,不能与2统一删除(1,2).因此,问题不在于它不会删除成员的所有;这是因为它不能同时与(1,2)和(1,1)统一(尝试删除[[((1,1),(1,2),(1,1),(3,2)],(1,_),列表).

(1,X) first unifies with (1,1). therefore, X is unified with 1 and cannot be unified with 2 to delete (1,2).so the problem is not that it does not delete all of the members; it's that it doesnt unify simultaneously with (1,2) and (1,1)(try delete([(1,1),(1,2),(1,1),(3,2)],(1,_),List).

顺便说一句,根据 swi-prolog手册:

此外,不建议使用delete/3:

also, delete/3 is deprecated:

因此,最简单的方法是编写您自己的谓词.像这样:

So the easiest way is to write your own predicate. Something like:

my_delete(Pattern,[Pattern|T],TD):-
   my_delete(Pattern,T,TD).
my_delete(Pattern,[H|T],[H|TD]):-
   my_delete(Pattern,T,TD).

也许?

检查排除/3,包含/3,分区/4

这篇关于序言删除:不会删除所有与Element合并的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:52