从序言中的列表中过滤掉大量数字
我想编写一个函数,通过删除小于或等于特定数字的所有内容来过滤数字列表。该函数将采用两个参数:数字列表和要过滤的数字。该函数应返回一个列表,其中包含大于过滤器编号的所有数字。
有时像这样:
filter_num_list(L1,N,L2) :- ...
test_filter_num_list :- filter_num_list([1,2,3,4,5,6,7,8,9],5,[5,6,7,8,9]).
I want to write a function which filters a list of numbers by removing everything less than or equal to a specific number. The function will take two parameters: a list of numbers and the number to filter. The function should returns a list which has all the numbers larger than the filter number.
Sometime like this:
filter_num_list(L1,N,L2) :- ...
test_filter_num_list :- filter_num_list([1,2,3,4,5,6,7,8,9],5,[5,6,7,8,9]).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另请参见库谓词,例如 include/3 和 except/3:
See also library predicates like include/3 and exclude/3:
使用 meta-predicate
tfilter/3
和具体化的clpfd 约束(# <)/3
,您可以跟上逻辑纯度并立即表达您想要的内容!这是我使用 SWI-Prolog 版本 7.1.37 运行的查询:
因为代码是 单调,我们还可以提出更一般性的问题并得到逻辑上合理的答案。
With meta-predicate
tfilter/3
and the reified clpfd constraint(#<)/3
, you can keep up logical-purity and express what you want in no time!Here's a query that I ran with SWI-Prolog version 7.1.37:
As the code is monotone, we can also ask more general queries and get logically sound answers.
尝试类似的东西:
try something like: