Thanks very much for that. I get it better now. I think. The SO link helped also, but the Ruby one made my head hurt.
What I'm taking from this so far is that
1. Closures preserve any enclosed variables from the original context where the closure was made (defined), rather than using the context of the call.
2. If you didn't have objects, you could use closures instead to capture the 'state' of different instances
3. With some trickery, you can use closures to introduce lazy evaluation. Which is good for computationally expensive functions that you want to forget about until needed.
I'm not sure if I'm right about those though. And I'd probably steer clear of deliberately exploiting closures cause I get a whiff of 'clever code' from the whole subject
What I'm taking from this so far is that
1. Closures preserve any enclosed variables from the original context where the closure was made (defined), rather than using the context of the call.
2. If you didn't have objects, you could use closures instead to capture the 'state' of different instances
3. With some trickery, you can use closures to introduce lazy evaluation. Which is good for computationally expensive functions that you want to forget about until needed.
I'm not sure if I'm right about those though. And I'd probably steer clear of deliberately exploiting closures cause I get a whiff of 'clever code' from the whole subject