Search code examples
c#.netlexical-closures

What does "lexical" mean in the statement "C# implements lexical closure"?


I'm reading about C# and closure, various articles, Jon Skeet's awesome "C# in Depth" and I see statements like "C# and ruby implement lexical closure".

Why do the authors include the word "lexical"? Why not just say they "implement closure"?

What would it mean if it just implemented "closure", and not "lexical closure (if that's even possible)?


Solution

  • Lexical closure is just a more specific name for closure.

    As you know, a closure allows a function to use variables from the scope where it was created, even if is executed from a different scope. Such a scope is also called a lexical environment, and that's where the term lexical comes from here.