in reply to Re^9: Accessing lexicals in other scopes dynamically by name
in thread Accessing lexicals in other scopes dynamically by name
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^11: Accessing lexicals in other scopes dynamically by name
by ikegami (Patriarch) on Jul 31, 2010 at 18:49 UTC | |
by morgon (Priest) on Jul 31, 2010 at 22:14 UTC | |
by ikegami (Patriarch) on Aug 01, 2010 at 06:34 UTC | |
by morgon (Priest) on Aug 02, 2010 at 00:54 UTC | |
by ikegami (Patriarch) on Aug 02, 2010 at 03:32 UTC |