lisp从列表中过滤掉不符合谓词的结果 [英] lisp filter out results from list not matching predicate

查看:211
本文介绍了lisp从列表中过滤掉不符合谓词的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图学习lisp,使用emacs方言,我有一个问题。
让我们说列表有一些成员,为此谓词评估为false。如何在没有这些成员的情况下创建一个新的列表?类似于 {A in L:p(A)是真的} 。在python中有过滤器的功能,在lisp中有什么等价物吗?如果不是,我该怎么办?



谢谢 这些函数在CL包中,需要(require'cl)来使用它们:

<$ p $ (1 2 3 4 5))


$ b(remove-if-not# $ b

这将返回一个新的列表,其中包含所有来自参数的偶数。



同样查找 delete-if-not ,它做同样的事情,但修改它的参数列表。


I am trying to learn lisp, using emacs dialect and I have a question. let us say list has some members, for which predicate evaluates to false. how do I create a new list without those members? something like { A in L: p(A) is true }. in python there is filter function, is there something equivalent in lisp? if not, how do I do it?

Thanks

解决方案

These functions are in the CL package, you will need to (require 'cl) to use them:

(remove-if-not #'evenp '(1 2 3 4 5))

This will return a new list with all even numbers from the argument.

Also look up delete-if-not, which does the same, but modifies its argument list.

这篇关于lisp从列表中过滤掉不符合谓词的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆