4 ms·
Ok let me take a stab at it. Variables are imagined as containers. Those variables/containers exist within a scope. Let's take an example where a room is the s
by pacaro 10y ago
Ok let me take a stab at it.
Variables are imagined as containers. Those variables/containers exist within a scope. Let's take an example where a room is the scope. That room is in an apartment, which is in turn in an apartment building, in a city and so on. Code whose scope is that room can access containers in that room, or in the open areas of the apartment (but not in other rooms without special arrangements being made), or in open areas of the building (but not in other apartments …) etc.
So code in my room can look inside a container in the hall, but not in a container in your room. And vice-versa.
A closure allows this special arrangement to look in another room. I can create a closure in my room. This is code that can access the containers in my room, but it has the special property that it acts like it is in my room even when it isn't. So I can give you this closure and you can run it in your room. When it's running in your room it can't access your containers (except as arguments) but it can still access the containers in my room.
My daughter is two. I'm looking forward to taking this journey with her