--
Mark Biggar
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]> On Wed, Aug 17, 2005 at 08:47:18AM -0700, Larry Wall wrote:
> > : >That could be made to work by defining constant to mean you can assign
> > : >to it if it's undefined. But then it gets a little harder to reason
> > : >about it if $pi can later become undefined. I suppose we could
> > : >disallow undefine($pi) though.
>
> If you can assign it when it contains an undefined value, bad
> things happen:
>
> sub f ($x is readonly) { $x = 10 }
> my $a; f($a);
>
> Compare this with:
>
> my $x is readonly;
> $x = 10;
>
> If it is defined as "bound to a immutable value cell", both cases
> above would fail, which is imho the easiest to explain.
Not only that, but what if what I want is a named constnat undef value?
> On Wed, Aug 17, 2005 at 08:47:18AM -0700, Larry Wall wrote:
> > : >That could be made to work by defining constant to mean you can assign
> > : >to it if it's undefined. But then it gets a little harder to reason
> > : >about it if $pi can later become undefined. I suppose we could
> > : >disallow undefine($pi) though.
>
> If you can assign it when it contains an undefined value, bad
> things happen:
>
> sub f ($x is readonly) { $x = 10 }
> my $a; f($a);
>
> Compare this with:
>
> my $x is readonly;
> $x = 10;
>
> If it is defined as "bound to a immutable value cell", both cases
> above would fail, which is imho the easiest to explain.
>
> > You could still reason about it if you can determine what the initial
> > value is going to be. But certainly that's not a guarantee, which
> > is one of the reasons we're now calling this write/bind-once behavior
> > "readonly" and moving true constants to a separate declarator:
> >
> > my $pi is readonly;
> > $pi = 3;
>
> The question remains, whether you can bind the readonliness away:
>
> my $pi is readonly; # undef at this point
> my $e is rw = 2.7;
> $pi := $e;
> $pi = 9;
>
> I can argue both sides -- rebindable is easier to implement, but
> non-rebindable is perhaps more intuitive.
>
> Thanks,
> /Autrijus/
>