C# Closures Explained
codethinked.com
codethinked.com
C# 3.0 greatly simplified things with the introduction of the lambda function syntax hence why a lot more people have suddenly "discovered" closures in .NET.
When first learning C# 2.0 I had a lot of difficulty understanding how to use delegates with closures mainly because I couldn't get past the syntax. Learning and using Python shortly after helped me tremendously in understanding how closures worked and when to use them because (not surprisingly) the Python syntax is so much cleaner and intuitive. I was able to then transfer and apply this knowledge to C# by cutting through the noise and using closures effortlessly (as needed). When lambdas arrived in 3.0, it was a no brainer.
This experience showed me how being exposed to and learning other programming languages that follow different paradigms can have a positive impact on how you write code in your primary language.
Anyhow, in Lisp, visually, a LET with it's enclosing parens makes it much faster to see the closed-over variables.
For example, in CL, this guy's example would take the general form:
(let ((counter 0))
(defun tally ()
(incf counter)))
So, in this form, I know that TALLY hides/closes over COUNTER, without needing to inspect the function body (either before, or within a λ that might be returned from within the function body).