我写返回所有列表的方法负奇数和积极 偶数删除(字符串可以留),由原始的筛选过程中使用lambda。我也在避免使用递归,但这是困扰我的东西。 我至今是:程序的列表(方案)
(define (f2b lst)
(cond ((null? lst)'()) ; if the list is empty, return the empty list
((pair? (car lst)) ; if the current element isn't a list
(filter (lambda (x) (or (even? x) (positive? x))) (car lst))
(filter (lambda (x) (or (odd? x) (negative? x))) (car lst)))
(else (string? (car lst)) ;otherwise, if the current element is a string,
(car lst) ; then return that element
(f2b (cdr lst)))))
我也不能确定我怎么能在同一时间同时应用的筛选过程。
我尝试运行此代码,但它只是通过我的测试用例并打印整个列表。编辑:我应该澄清,我通过嵌套列表运行它。 – user2789945
@ user2789945:你运行了我给的最后一个函数?你给了它什么输入? – Claudiu
是的,它适用于常规列表,但是当我通过它通过一个嵌套列表,它打印的整个列表。 – user2789945