I was just refering to an implementation of Scheme in Scheme in which for every lexical scope a data-structure (called an "environment") was created which basically is a symbol-table. This symbol-tables also point back to the symbol-table of the enclosing lexical scope and this link is then followed when one has to look up a symbol which is not found in the current scope.
This symbol-table is always needed by the interpreter to keep the variable-bindings - regardless of whether there are closures or not - and can be used to implement closures.
In such a scenarion a closure would simply refer to an already existing data-structure containing all variable-bindings - so the number of variables is irrelevant for the cost of creating a closure and >>all<< variable bindings are available to the closure.
Naively I had assumed that this was a standard technique and Perl would do the same thing, which is why I was surprised when you demonstrated that there are lexial variables that are defined when the closure is created, yet are not accessible to it because Perl could not "see" that the closure would reference them indirectly.
In reply to Re^10: Accessing lexicals in other scopes dynamically by name
by morgon
in thread Accessing lexicals in other scopes dynamically by name
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |