While Dominus is in part right that the discussion on perl6-language-strict could have been more productive, there are indeed issues that make this less than easy to do.

I'm working on a paper for this, so I don't want to give everything away early, but the basic upshot is that there are three languages often mentioned in the same breath as Perl that do make variables lexical by default, each in different ways. And, as you might imagine, each of them has their own problems.

Python has only two real scopes -- global and nearest-enclosing-block lexical. If Perl went this way, we would lose a *lot* of flexibility.

Ruby does a better job with scopes, but it is very easy to create action-at-a-distance problems. I.e. you write a function that has a tightly enclosed lexical scope. A year later, you add a variable 300 lines above it that happens to have the same name as a variable in that tight lexical scope, and all of the sudden the two variables are the same -- you've inadvertently changed the scope of a lexical.

Tcl gives the most flexibility of the three, but you end up with all kinds of `upvar' nonsense to try and place variables in the scopes you want them. Easy to screw up and also very verbose.

In sum, there are possibly better ways to do it than the way Perl does it now, but figuring out the semantics that are best is far from easy.

I hope to finish my paper sometime soon, and if people are interested I'll post it here for comments before I make it public. It will hopefully be able to suggest a reasonable semantic for Perl 6.

-dlc


In reply to Re: Default Scope Behaviour by dchetlin
in thread Default Scope Behaviour by NeoPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.