in reply to Re^5: Accessing lexicals in other scopes dynamically by name
in thread Accessing lexicals in other scopes dynamically by name

Hmm.

I have never really looked at the Perl-internals, but I can vagly remember having seen an implementation of Scheme in Scheme.

If I remember correctly there was a data-structure containing all the variable-bindings for any lexical scope and every closure would simply keep a reference to this.

So in this approach there is not a "capturing of all lexicals" but simply remembering one data-structure regardless of how many variables were defined it.

Perl evidently does this differently and I even think that the inaccessabilty of certain lexial variables of which Perl could not see that the are going to be used in a closure is a weakness.

I will try this in Rakudo.

  • Comment on Re^6: Accessing lexicals in other scopes dynamically by name

Replies are listed 'Best First'.
Re^7: Accessing lexicals in other scopes dynamically by name
by ikegami (Patriarch) on Jul 30, 2010 at 22:20 UTC

    So in this approach there is not a "capturing of all lexicals" but simply remembering one data-structure regardless of how many variables were defined it.

    You forgot the bit about placing them in the data structure to being with.

      You forgot the bit about placing them in the data structure to being with.
      I made it not clear I think.

      This structure is initialized when a new lexial scope is encountered (pointing back to the enclosing environment) and new variable bindings are added whenever a new lexial variable is defined.

      It exists whether or nor a closure is created.

      All closures within this context then simply remember a reference to this structure and use it to look up variables.

      But Perl evidently does it differently it does not really matter..

        It exists whether or nor a closure is created.

        You're talking about making references to variables all over the place to replace a few when an anon sub is created. That's a very big negative.