On Sat, Sep 16, 2000 at 03:24:32AM -0000, Perl6 RFC Librarian wrote:
> 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 :-)

    ${$pkg.'::'.$var} = $val;
    ${"$pkg\::$var}   = $val;

Still ugly, but not quite as bad as what you came up with.


> =head1 NOTES ON FREEZE
> 
> The first part of this RFC, interpolated method calls, was superceded by
> RFC 222: "Interpolation of method calls", by Michael Schwern.

Ooop, didn't even notice and didn't see the discussion.  Let me see if
I missed anything... I didn't discuss class methods as opposed to
object methods.  Will ponder.


> In a perfect world, these should work in Perl 6:
> 
>   $var = 'RaiseError';
>   $DBI::$var = 1 ;               # $DBI::RaiseError = 1

Uh oh.  Symbolic references!!!  These carry enough caveats and are
abused so often (95% of the time you want a hash) that I'd rather they
were left amongst the "hard things possible" section of Perl.

Its a common newbie mistake to do something like this:

    $var1 = "this";
    $var2 = "that";
    $var3 = "wibble";

    foreach $num (1..3) {
        print ${"var".$num};
    }

Rather than use an array or hash, many people abuse symbolic
references.  It happens frequently enough now, if its make simpler,
the abuses will increase.


>   $pkg = 'Class';
>   $var = 'DEBUG';
>   ${${pkg}::$var} = 1;           # $Class::DEBUG = 1
> 
>   $subpkg = 'Special';
>   $class = $pkg . '::' . $subpkg;
>   require $class;                # require Class::Special

Ambiguous.  Consider the following:

    $class = "Class::Special";
    $file  = "lib/foo/bar.pl";

    require $class;  # want:  load "Class/Special.pm" from @INC
    require $file;   # want:  load "lib/foo/bar.pl" from @INC

The only way Perl can (currently) know if you're requiring a module or
a literal file is because of the bareword.  Your proposal would
require that all requires be considered modules, which isn't feasible.

You could have require() differenciate by whether or not the EXPR
matches /::/, but that stinks of a special case.  

C<eval "require $class"> isn't that hard, but I wouldn't mind seeing a
more obvious way.


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

This combines the problems of symbolic references PLUS busting
encapsulation.  Shouldn't be easy.


-- 

Michael G Schwern      http://www.pobox.com/~schwern/      [EMAIL PROTECTED]
Just Another Stupid Consultant                      Perl6 Kwalitee Ashuranse
Maybe they hooked you up with one of those ass-making magazines.
        -- brian d foy as misheard by Michael G Schwern

Reply via email to