The following RFC reflects an assumption I've been making about
where Perl6 will go.  Feel free to shoot it down, if I'm the only who
feels this way. :)

=head1 TITLE

Lexical variables made default

=head1 VERSION

 Maintainer: J. David Blackstone <[EMAIL PROTECTED]>
 Date: 1 August 2000
 Version: 1
 Mailing List: perl6-language
 Number: unassigned

=head1 ABSTRACT

Prior to version 5, all implementations of Perl were designed with
only dynamic variables in mind.  Perl5 provided lexical variables in a
backward compatible way.  Perl6 should make lexical variables the default.

=head1 DESCRIPTION

Dynamically-scoped variables can have many effects which are
counterintuitive and undesirable.  In Perl5, lexically-scoped
variables are available with the C<my> operator, meaning the
programmer has to go to extra lengths to use this feature.  There are
very few circumstances in which dynamic variables have a distinct
advantage over lexicals.

In Perl6, every variable should be lexical unless otherwise specified.
 Variables should only be visible within the scope in which they are
defined (the enclosing block, method, or file).

Dynamic variables and the misnamed C<local> operator should still be
permitted in Perl6, but extra syntax should be required to specify a
variable as dynamic, just as Perl5 currently requires analogous extra
syntax for lexical variables.

=head1 IMPLEMENTATION

I don't know enough about internals to say anything about
implementation from that standpoint, but I believe a few words are in
order as to how this should look in the language.

=head2 Lexical variables

Any variable should automatically be lexical.  The C<my> keyword could
still be used in order to declare a variable, along with a C<strict>
pragma or something analogous to force declaration of all variables.

As an example, the following variables are lexical:

    $number =  15;
 my $string = "foo";
 $obj = Class->new();
 my Dog $spot = new Dog();

The final line may or may not be a part of Perl6 syntax, as decided elsewhere.

=head2 Dynamic variables

Dynamic variables would have to be specifically declared.  Perl5
currently uses the C<vars> pragma to declare dynamic variables, as
well as the C<our> keyword.  (XXX Someone help me out; C<our> didn't
work the way I expected, and I still don't understand it because I
haven't had time to learn. :( )

Perl6 could choose a pragma or keyword to declare dynamic variables.

The C<local> operator should be retained due to its usefulness for
dynamic scoping, but should be renamed to avoid confusion.  I'm
currently suggesting a name of C<dynsave>.  More euphonious
suggestions are requested.

This RFC needs to include some specific examples of syntax used to
declare dynamic variables, as soon as such syntax is finalized.

=head1 REFERENCES

The section on "Private Variables via my()" in the perlsub manpage.

The Camel book.

Reply via email to