【发布时间】:2012-10-31 00:40:28
【问题描述】:
我一直在进行累积调用,如下所示:
(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))
但是,当我尝试通过过滤器选择某些东西来解决问题时,答案不起作用。我到目前为止是这样的:
(define (f2b items)
(accumulate (lambda (x y)
(cons (append
(map square (filter negative? (filter number? x))) x) y)) () items)
)
我给出的输入是:
(f2a '(("sdas" 89) (-53 "sad")))
我得到的输出是:
((sdas 89) (2809 -53 sad))
我似乎无法让负数消失。
【问题讨论】:
-
你的输入是什么?看起来您有一个包含两个列表的嵌套列表,但您的代码无法处理。
-
@GregHewgill 我输入了我提供的信息。
标签: list scheme mit-scheme accumulate