alpineranger
Senior member
For my own curiosity I'm going over some material I haven't touched in years. I'm a bit puzzled by the behavior of lambda functions. I can use them in basic ways, but my understanding is really lacking. For example, given the following expression:
( (lambda (y) (lambda (x) (+ x y)) 4) 5)
=> 4
I don't understand this result, as by my reckoning this should be equivalent to:
( (lambda (y) (+ 4 y)) 5)
=> 9
Basically, how does the binding of variables occur in this case. I've read the R5RS on lambda and it doesn't clarify things.
I know I can do something like:
( (let ((x 4)) (lambda (y) (+ x y)) )5 )
=> 9
but with the nested lambdas I'm baffled by the mechanics of binding. (Apologies for the potentially confusing use of parentheses)
( (lambda (y) (lambda (x) (+ x y)) 4) 5)
=> 4
I don't understand this result, as by my reckoning this should be equivalent to:
( (lambda (y) (+ 4 y)) 5)
=> 9
Basically, how does the binding of variables occur in this case. I've read the R5RS on lambda and it doesn't clarify things.
I know I can do something like:
( (let ((x 4)) (lambda (y) (+ x y)) )5 )
=> 9
but with the nested lambdas I'm baffled by the mechanics of binding. (Apologies for the potentially confusing use of parentheses)