This and other RFCs are available on the web at
http://dev.perl.org/rfc/
=head1 TITLE
Eliminate unquoted barewords from Perl entirely
=head1 VERSION
Maintainer: Nathan Wiger <[EMAIL PROTECTED]>
Date: 24 Sep 2000
Mailing List: [EMAIL PROTECTED]
Number: 277
Version: 1
Status: Developing
=head1 ABSTRACT
Currently, there is considerable syntactic ambiguity in Perl when
dealing with barewords:
print STDERR @a; # STDERR->print(@a) or print STDERR(@a) ?
name->stuff(@b); # name()->stuff(@b) or 'name'->stuff(@b) ?
$time = time; # time() or 'time' ?
This is because of the inherent ambiguity between barewords and function
names.
Some have suggested highly-specific solutions, such as eliminating
bareword indirect object syntax and making -> quote the left operand.
However, these only address specific symptoms of a greater problem, and
in doing so add even more special cases to Perl's syntax, which we don't
need.
The solution is simple: All barewords must die.
=head1 DESCRIPTION
=head2 Why This Sucks
There are many instances of barewords being widely-used, sometimes as
functions and sometimes as literals. This proposal would create a big
burden on the programmer:
Perl 5 Perl 6
-------------------------------- --------------------------------
$q = new CGI; $q = new 'CGI';
$q = CGI->new; $q = CGI::->new;
$q = 'CGI'->new;
$r = Apache->request; $r = Apache::->request;
$r = 'Apache'->request;
print STDERR "Hello!"; print &STDERR("Hello!") # or...
print 'STDERR' "Hello!"
$now = time; $now = time();
print; print();
$num = shift->{number}; $num = shift()->{number};
$mode = stat->{mode}; $mode = stat()->{mode};
What is this, C? Gimme a break.
=head2 Why This Doesn't Suck
Nobody - including me - wants to do that crap. However, settling for
anything less results in many more syntactic ambiguities and problems
being introduced than solved.
So, we introduce a simple lexically-scoped pragma, C<bareword>, which
indicates how we want barewords to be interpreted:
use bareword 'literals'; # barewords are literal strings
use bareword 'functions'; # barewords are functions
There is no C<'all'> for C<use bareword> - it is an either-or choice.
By default, it is off, meaning that barewords cannot be used and will
result in a syntax error.
=head2 use bareword 'literals'
Under this rule of the pragma, all barewords are I<always> interpreted
to be literal strings. So the above code would be interpreted as:
use bareword 'literals';
$q = new CGI; # $q = 'CGI'->new;
$q = CGI->new; # $q = 'CGI'->new;
$q = CGI::->new; # $q = 'CGI::'->new;
$r = Apache->request; # $r = 'Apache'->request;
$u = Apache->request->uri; # $u = 'Apache'->'request'->uri;
$num = shift->{number}; # $num = 'shift'->{number};
$count = want->{count}; # $count = 'want'->{count};
$mode = stat->{mode}; # $mode = 'stat'->{mode};
print STDERR "Hello!"; # 'STDERR'->print("Hello!");
print 'STDERR' "Hello!"; # 'STDERR'->print("Hello!");
$now = time; # $now = "time";
print; # "print" in void context
Onto the next choice...
=head2 use bareword 'functions'
Under this rule, all barewords are I<always> interpreted as functions.
So the above examples would be parsed as:
use bareword 'functions';
$q = new CGI; # $q = new(CGI());
$q = CGI->new; # $q = CGI()->new();
$q = CGI::->new; # $q = 'CGI::'->new(); # *
$r = Apache->request; # $r = Apache()->request();
$u = Apache->request->uri; # $u = Apache()->request()->uri();
$num = shift->{number}; # $num = shift()->{number};
$count = want->{count}; # $count = want()->{count};
$mode = stat->{mode}; # $mode = stat()->{mode};
print STDERR "Hello!"; # print(STDERR("Hello!"));
print 'STDERR' "Hello!"; # 'STDERR'->print("Hello!");
$now = time; # $now = time();
print; # print();
Note that the one marked with a * can be accomplished since C<::> is not
a valid C<\w+> character. As such, it can be considered not a bareword
and not in need of quoting.
=head2 Final Notes
Choose your poison, you can't have it both ways. Injecting Perl with
even more syntactic ambiguities is not the way to go. Perl's syntax
needs B<fewer> special cases, not more.
If neither of these options sounds particularly appetizing, then I
suggest we leave things as-is. There are already numerous alternatives
for disambiguating indirect objects and bareword functions.
If this were to be adopted, I don't particularly see a use for
C<bareword 'literals'>, so perhaps the best approach is simply to make
C<bareword 'functions'> the way Perl 6 is implemented.
=head1 IMPLEMENTATION
Hold on.
=head1 MIGRATION
Ditto.
=head1 REFERENCES
RFC 28: Perl should stay Perl.
RFC 244: Method calls should not suffer from the action on a distance