2010-09-27 109 views
1

這一直使我絕對堅果。我有一個替代的功能是這樣的:嵌套函數調用

(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) 

這是我的功課只有很小的一部分。

我一直在使用與拉姆達功能的地圖嘗試過,但每次我試過的方法給我留下的東西,如:

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

我需要調用這個直到x列表爲空。 我不知道爲什麼這個想法讓我感到非常沮喪,任何幫助都非常感謝。

回答

0

從長度= 2的示例中,我認爲泛化類似於(foldr mysub body x bind),它將mysub應用於xbind中的每對值。

使用map在這裏不起作用,因爲您需要通過每個mysub呼叫傳遞「當前」值body