On Thu, Aug 18, 2005 at 12:02:53AM +0800, Autrijus Tang wrote:
: 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.

Though I think most people have a pretty good understanding of "worm"
these days, what with CD and DVD burners...

"Darn, I turned my third parameter into a coaster.  Now what am I gonna do?"

: > 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.

English has a long history of hoisting the adjectives from the object
to its container.  "I'd like a nice cup of tea" and such.  So in general
I think people will expect a readonly variable to contain a readonly
value, and maybe we should do the extra work to enforce that transitively.

That being said, there's also a history of rebinding references, as
in "That woman is a man!"  But we intuitively recognize that there's
something funny going on there linguistically.  We can deal with it
as humans, but maybe we can allow the soulless computer to throw a
exception on such contradiction instead of laughing like we do.

That being said, it's still quite possible that

    my $pi is readonly;

realizes that it's not bound to anything reasonable yet, and set
up a "worm" container of some sort that binds lazily at run time.
As with parameter defaults, it's more about whether the container's
value exists than whether it's defined.


Reply via email to