Functional programming 嵌套函数调用
这简直让我发疯。我有这样一个替代函数:Functional programming 嵌套函数调用,functional-programming,lambda,scheme,Functional Programming,Lambda,Scheme,这简直让我发疯。我有这样一个替代函数: (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
(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)
我需要像这样调用函数:
(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列表为空。
我不知道为什么这个想法会让我如此困惑,非常感谢任何帮助。从长度为2的示例中,我认为泛化类似于
(foldr mysub body x bind)
,它将mysub
应用于x
和bind
中的每对值
使用map
在这里不起作用,因为您需要通过每个mysub
调用传递body
的“当前”值