【发布时间】:2013-11-10 19:21:30
【问题描述】:
我正在编写一个程序,它返回一个包含所有负数和正数的列表 通过在原始过滤器过程中使用 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)))))
我也不确定如何同时应用这两个过滤程序。
【问题讨论】: