Eliminate dynamic variables entirely?
[email protected] ("J. David Blackstone") Mon, 14 Aug 2000 16:57:16 -0500
| Newsgroups | perl.perl6.language.strict |
|---|---|
| Message-ID | <[email protected]> |
Here's a radical thought: In most languages, dynamic scoping of variables offers no advantages over lexical scoping, other than dynamic assignment. Dynamic assignment can be accomplished with the local() operator (soon to be renamed, I hope). The local() operator can be extended to operate on lexical variables as well as (or instead of; read on ...) dynamic variables. The package command was created in order to allow for different namespaces that would not conflict, back when lexical variables were not available at all in Perl. Now it has been extended for O-O classes. The following changes could be made involving lexical variables and packages in order to eliminate dynamic variables from the language entirely: *) Dynamic variables no longer exist. *) Lexical variables belong to the package they are declared in. (Or, if not declared, the package to which they belong can be inferred.) *) Lexical variables can only be accessed from within the same scope or a lower scope. This means lexicals declared in the same file can be accessed if they belong to a different package, but lexicals declared in another file cannot be accessed directly. *) In nearly all cases (hopefully approaching the magic 80% translate 100% correctly, 95% translate 95% correctly), a package (dynamic) variable can be translated into a lexical variable defined in a .pm file along with a class accessor method (standard get/set functionality). I'm thinking cases where this wouldn't work, if there are any, would be so esoteric that someone would want to port them by hand, anyway. *) Packages still continue to function in the same way to define classes. *) Packages still continue to provide a separate namespace for non-O-O subroutines. This enforces the lexically-scoped variable paradigm even more, and best of all, *the implementers only have to worry about one type of variable!* Perl could cease to look like lexical variables were hacked onto the side to fix a problem. If people really want true dynamic variables, there could be a pragma. ... Results are left to the imagination. (In this case, I suppose Perl would look like lexical variables designed in with dynamic variables hacked onto the side. Still an improvement, I think.) Still trying to cause trouble, J. David