So next year, we'll probably have let statements in most of our systems.
And here, we've got two blocks. One inside of the other and the inner block can see its variables, and the variables of the outer block. So, I assume everybody is comfortable with the idea of block scope. We've had that since and it's great. So, we can do the same thing with functions. You can think of a function as simply being a block with a little bit of extra mechanism attached to it, so that you can invoke it in the future.
So we've got the yellow function, which can see a and b and the green function that can only see a.
Exactly the same relationship and we can represent this relationship as sets. So, this is the set of variables that the outer function can see and this is the set of variables that the inner function can see.
And it's kinda too bad that we call it closure, cuz most people think of closure as meaning something else, like retribution or vengeance.
But it's not that kind of closure, but that's what we're calling it. So, we're kind of stuck with that and it seems like a simple idea.
What is lexical scoping?
Just add nested functions, which have what should be an obvious relationship, because of the way that scope works, but it took a long, long time for this idea to get developed. He needed lexical scoping. He needed nested functions and functions, as first class values. And pretty early on, we got functions that would have two out of three, but we didn't get a function that had all three until scheme.
Scheme was an experiment at MIT in an attempt to understand Carl Hewitt's after model in their early 70s. And like all of the really important, significant breakthroughs, the world took no notice of it whatsoever.
Block Scopes and Function Scopes Now there are two main types of scopes in programming - block scopes and function scopes. The scope in the previous example was a block scope. It's just a block of code. Block scopes are immediately executed.
Function scopes on the other hand are templates of block scopes.
programming practices - Why would a program use a closure? - Software Engineering Stack Exchange
It doesn't have block scopes.