删除列表中未分配的成员 [英] Delete an unassigned member in list
问题描述
我写了一个代码,以获得一些特定的输出(2个列表),它的工作,并给我我需要的东西,但是两个列表中有未分配的元素,如下所示,所以我的问题是:如何删除这些未分配的元素.
i write a code , to get some specific output (2 List) , and it's work , and give me what i need , but there are unassigned element in the two list ,as shown below ,so my question is : how to delete thess unassigned elements .
Courses = [_G1619, linear, _G1607, physics2, physics1, calculas1|_G1590],
Marks = [_G1622, 78, _G1610, 90, 80, 78|_G1593]
推荐答案
在 SWI-Prolog 中有一些列表处理实用程序,例如 exclude/3,允许指定要在每个元素上使用的谓词.var/1 似乎合适.例如
In SWI-Prolog there are some list processing utilities like exclude/3, that allow to specify a predicate to be used on each element. var/1 seems appropriate. For instance
2 ?- exclude(var,[1,A,B,2,3|L],R).
L = [],
R = [1, 2, 3] ;
...
(注意:在调用后进行剪切以消除不确定性).
(note: place a cut after the call to get rid of nondeterminism).
我惊讶地发现它也删除了无界尾部——我认为它需要一个适当的列表.那么它应该符合您的要求.
I was surprised to find it also removed the unbounded tail - I thought it would require a proper list. Then it should fit your request.
这篇关于删除列表中未分配的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!