[% setvar title Fix C<$pkg::$var> precedence issues with parsing of C<::> %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


Fix $pkg::$var precedence issues with parsing of ::


  Maintainer: Nathan Wiger <nate@wiger.org>
  Date: 14 Aug 2000
  Last Modified: 23 Sep 2000
  Mailing List: perl6-language@perl.org
  Number: 103
  Version: 3
  Status: Retracted
  Frozen since: v2


Currently, trying to dynamically assign to unnamed classes is very difficult:

   $pkg::$var = $val;         # error
   ${pkg}::$var = $val;       # nope
   ${$pkg::$var} = $val;      # you wish
   ${${pkg}::$var} = $val;    # sorry
   ${"${pkg}::$var"} = $val;  # works, but bleeech :-)

The precedence and parsing of the :: operator should be fixed to allow easy access to anonymous package operations.


I don't see any easy way of getting this to work without causing potentially really hairy problems with precedence. In particular check out:


Which is actually a reply to Schwern's post, but that appears to be gone from the mail archives forever...


In a perfect world, these should work in Perl 6:

  $var = 'RaiseError';
  $DBI::$var = 1 ;               # $DBI::RaiseError = 1

  $pkg = 'Class';
  $var = 'DEBUG';
  ${${pkg}::$var} = 1;           # $Class::DEBUG = 1

  $subpkg = 'Special';
  $class = $pkg . '::' . $subpkg;
  require $class;                # require Class::Special

  $mypkg = 'Some::Package::Name';
  $ret = $mkpkg::do_stuff(@a);   # is &{"${mypkg}::do_stuff"}(@a) now  

Currently, the precedence of :: does not allow these operations. Some of the above examples may still require additional braces, but they shouldn't require the types of contortions currently needed.


Unfortunately, I don't have the time to think this part up yet. :-( I will gladly contribute to the precedence and parsing rules discussions that will ensue in the future if this RFC is accepted.


Programming Perl, 2ed, for the ${"${pkg}::$var"} syntax

RFC 222: Interpolation of method calls