<< Previous exercise (3.67) | Index | Next exercise (3.69) >>

Louis' implementation will recurse infinitely simply because interleave is an ordinary *function*, not a special form like cons-stream, and hence will need to fully evaluate both arguments first, since Scheme uses eager evaluation for ordinary functions. Since the second argument to interleave is a recursive call to pairs, and there is no hard-coded base case, this implementation will recurse infinitely.

mart256

I disagree @meteorgan. interleave returns a cons-stream, then it has delay. Anyway, I think this solution won't work either, because it will produce the following sequence:

The recursive call is always going to call to the second element of interleave, because there is no 'pivot' to do an interleaving, thus it leaves out elements like

(3,4) (3,5)...(4,5) (4,6)...and so on.anon

@meteorgan is correct here. interleave returns a cons-stream, but interleave will never be successfully called since its second arg (pairs ...) will be evaluated first. Attempting this evaluation will result in recursion sans base-case.