views:

63

answers:

1

Hey all,

This has been driving me absolutely nuts. I have a substitute function like this:

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

I need to call the function like this:

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

This is only small part of my homework.

I've tried using a map with lambda functions, but every approach I've tried leaves me with something like:

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

I need to call this until the x list is empty. I don't know why this idea is tripping me up so much, any help is greatly appreciated.

A: 

From the example with length=2, I think the generalization is something like (foldr mysub body x bind), which applies mysub to each pair of values in x and bind.

Using map doesn't work here, because you need to pass around the "current" value of body through each mysub call.

hzap