in reply to Re: Rules of Lexical Scoping
in thread Rules of Lexical Scoping

Lexical variables aren't discarded and recreated. They are simply cleared.

I think that ysth has adequately answered that objection, but I would answer it this way: All of that happens under the hood; it has no user-visible effects. In any way that a perl programmer can tell, perl behaves just as ysth has described.

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^3: Rules of Lexical Scoping
by ysth (Canon) on Nov 11, 2007 at 22:51 UTC
    I personally believe that ysth has adequately answered that objection, but I would answer it this way: All of that happens under the hood; it has no user-visible effects. In any way that a perl programmer can tell, perl behaves just as ysth has described.
    s/ysth has described/dave_the_m has described/.

    Also "has no user-visible effects" is an overstatement; should have no user-visible effects is more accurate. The rules describe how things should work; there may be bugs, and (as in the case of my $foo if 0;) there are things you can (but shouldn't) do to expose rule violations that for various reasons won't be fixed.

      s/ysth has described/dave_the_m has described/

      I presume you're alluding to this; I was merely referring to your root in this thread.

      there may be bugs

      Granted.

      A word spoken in Mind will reach its own level, in the objective world, by its own weight
Re^3: Rules of Lexical Scoping
by ikegami (Patriarch) on Nov 12, 2007 at 04:47 UTC

    "3. At the creation time of a sub that references an outer lexical" as opposed to "3. At the creation time of a sub in scope of an outer lexical" is also an optimization that also has little user-visible effect.

    ysth posted (in part) to explain the low-level details behind the sub { eval '$i' } problem.
    I posted to explain the low-level details behind the my $i if $expr; problem.

    I don't see my post as being out of place, although I'll grant you that my opening ("I think that's quite inaccurate.") could have been worded better.

      When I read "Each time a block with a 'my' declaration is entered, a new instance of that lexical is created", my first reaction was very much "I think that's quite inaccurate".

      I also quite disagree with the assertion that "it has no user-visible effects" and not just because you demonstrated some in your reply. The only reason I knew that the original description was inaccurate was because I had answered nodes from users who ran into things (which means they were user-visible) that, in order to explain, I had to make those specific effects more obviously visible.

      - tye        

        I am curious to know what those things were that users ran into, and if they are fixed in 5.10.0 (which definitely has some scoping fixes in it), if you have the time and energy to track down some of your answers.