Re: RFC 154 (v1) Simple assignment lvalue subs should be on by default
[email protected] (Nathan Wiger) Thu, 24 Aug 2000 12:00:56 -0700
| Newsgroups | perl.perl6.language.subs |
|---|---|
| Organization | Sun Microsystems |
| Message-ID | <[email protected]> |
Chaim Frenkel wrote:
>
> Why this limitation?
>
> If the lvalue is a fundemental type (whatever that is) everything works
> as if the lvalue were actually in place
>
> sub foo { return $a }
> foo =~ s///; # same as $a =~ s///;
This is not the type of lvalue sub that this RFC proposes be enabled by
default. This is a "true" or "complex" lvalue sub.
My RFC proposes that this sub:
sub assign ($var, $val) {
my $oldval = self->{STATE}->{$var};
self->{STATE}->{$var} = $val if $val;
return $oldval;
}
Can be called as any of these forms by default:
$old = assign($var, $val);
$old = assign($var) = $val;
$old = assign = $var, $val;
Make sense? This RFC doesn't address true lvalue subs, rather that
rvalue subs should be able to be used in an lvalue assignment context by
default. It is a limited but valuable syntactical tool.
-Nate