【发布时间】:2013-01-06 04:38:53
【问题描述】:
下面是我尝试创建一个过程,该过程返回给定方案中的函数列表的函数组合。我陷入了僵局;我写的东西在纸上是有道理的,但我看不出哪里出错了,谁能给点建议?
; (compose-all-rec fs) -> procedure
; fs: listof procedure
; return the function composition of all functions in fs:
; if fs = (f0 f1 ... fN), the result is f0(f1(...(fN(x))...))
; implement this procedure recursively
(define compose-all-rec (lambda (fs)
(if (empty? fs) empty
(lambda (fs)
(apply (first fs) (compose-all-rec (rest fs)))
))))
where ((compose-all-rec (list abs inc)) -2) should equal 1
【问题讨论】:
-
您是否了解过用于解决此类问题的设计方法或其他正式方法?请参阅:ccs.neu.edu/home/matthias/HtDP2e/index.html 例如,您可能想要考虑一些具体的测试用例。具体来说,在给定一些简单输入的情况下表达预期输出。您已经直接进入编码领域,而对于比单行代码更大的问题,这通常是一种有问题的方法。
-
空箱的具体例子:
(compose-all-rec (list))应该是什么?你期望((compose-all-rect (list)) -2)是什么?
标签: recursion functional-programming scheme racket