Edward Peschko writes:
: Why can't variable properties and value properties be the same thing?

Because a variable is a container, and has properties appropriate to
a container, and a value is a containee, and has properties appropriate
to a containee.  (Plus, any given value could be in multiple variables
simultaneously.)

It's the same basic distinction between tying and overloading.  Tying
is something that happens on a container object, and overloading is
something that happens on a value object.

: $ARGS is chomped;
: $ARGS.chomped = 1; # same difference

Fine, that's a value property, because $ARGS is a simple scalar
variable that doesn't particularly care that it's pointing to a magical
filehandle object.

: my $string = "value";
: print $string.value;  # prints 'value'

That seems a bit odd, since .value is a no-op, unless you want to
differentiate the variable prop hash

    $string.prop

from the value's prop hash

    $string.value.prop

But see my previous message about that.

: my $num = 0 is true;
: print $num.true;  # prints 1;

You've set a variable property there, so any value in it will appear to
be permanently true.  So the following would not do what you want:

    sub myfunc { return 0 is false }

    my $num = 0 is true;        # sets variable "true"
    $num = myfunc();            # sets value "false"
    print $num.true;            # still prints 1, known at compile time

In fact, the optimizer would turn that into

    print 1;

: print %{$num.prop}    # prints all of the properties/attributes associated 
:                       # with an object.

Which object?  There are two of them, both with the name $num.  Usually
this is not an issue, because lvalue context means the variable, and
rvalue context means the value.  In this case, we need to distinguish
the objects some other way.

It's really important to keep variable properties separate from value
properties, especially when you temporize a variable:

    our $foo is variablemagical;
    $foo = 1 is valuemagical1;
    {
        temp $foo = 2 is valuemagical2;
        ...
    }

After the temp, $foo is still variablemagical, and valuemagical2, but
it's not valuemagical1 again until the temp scope is exited.  Even
Perl 5 has to be careful about which magics it localizes and which
ones it doesn't.  Tainting belongs to the value, and tying belongs
to the variable.

Larry

Reply via email to