Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Default Scope Behaviour

by dchetlin (Friar)
on Jan 01, 2001 at 06:54 UTC ( #49154=note: print w/replies, xml ) Need Help??

in reply to Default Scope Behaviour

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://49154]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-06-21 11:32 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.