【问题标题】:Nesting Function Calls嵌套函数调用
【发布时间】:2010-09-27 09:25:54
【问题描述】:

这一直让我发疯。我有一个这样的替代函数:

(define (mysub x bind body) ;;  x, bind, body are lists
  ...)

我需要这样调用函数:

;;this is the explicit call for when length x = length bind = 2.
;;how do I generalize these nested calls?

;;in case it's not obvious, i'm passing mysub as the third parameter 
;;to a previous mysub call

(mysub (first x) (first bind) (mysub (first (rest x)) (first (rest bind)) body)

这只是我功课的一小部分。

我尝试过使用带有 lambda 函数的地图,但我尝试过的每一种方法都给我留下了类似的东西:

( (x1)(bind1)(body) (x2)(bind2)(body) ) ;;I've found a million ways to get this

我需要调用它,直到 x 列表为空。 我不知道为什么这个想法让我如此困惑,非常感谢任何帮助。

【问题讨论】:

    标签: functional-programming lambda scheme


    【解决方案1】:

    从长度为 2 的示例中,我认为泛化类似于(foldr mysub body x bind),它将mysub 应用于xbind 中的每一对值。

    在这里使用map 不起作用,因为您需要通过每个mysub 调用传递body 的“当前”值。

    【讨论】: