What is the difference between two functions in Scheme, one defined like this—
(define doSomething
(lambda (x)
(let (f (100))
(f x))))
and the other like this?—
(define doSomething
(let (f (100))
(lambda (x)
(f x))))
In other words, what does it matter if the lambda is before the let or after it?
Your code won’t run. 🙂
I will presume that you mean these instead:
and
In both cases, you’ll get back the passed-in argument plus 100.
However, the main difference (ignoring technicalities about how
letis just syntactic sugar overlambda) is that in the second version,fis a free variable. Say we do this:This returns a list with two lambdas: the first of which is just like the ones previously, and the second one which allows you to change the value of
f. Both lambdas access the samef, so running the setter will affect later calls to the first lambda.