<nitpicky>A semantic definition of "constant" would be nice.</nitpciky>
I'd like to propose the following definition:
A constant value cannot be assigned to, deleted, or used as the argument to
a mutating function/operator.
Doing any of these would be a catchable error. (However, it can be deleted
by the GC, and thus may have a
DESTROY method.)
It cannot be local()ized, unless the "localizable" flag was given, IE
my $foo = 42 : constant(localizable); (This should be an error sepperate
from "cannot localize" and "assignment to a constant".)
Note that I use the word "value" and not "variable".
I suggest that additionaly, in a hash if a key is constant, it means that
the key cannot be deleted, but it's value can be changed. To make the whole
pair constant, set the value to be a constant -- removing the key would
imply deleting the value as well, which is an error.
A hash being constant, or a list being constant implies that all of it's
members are constant.
A ref to a thingy being constant is different from a ref to a constant
thingy.
The constant attribute can never be removed from a variable once it is set.
The localizable flag cannot be added later, but can be removed.
There may be other flags in the future; their addablity/removeablility is
not defined.
The constant attribute is rather odd in that normaly, somthing of the form
"my $foo = 42 : attrib" creates $foo, sets it's "attrib" attribute, and then
assigns 42 to it.
OTOH, the constant attribute is set after the assignment -- otherwise the
assignment would
always be in error!
-=- James Mastros