On 8/16/06, Darren Duncan <[EMAIL PROTECTED]> wrote:
Both the === and eqv operators test the actual values of 2
containers, but that their semantics differ in regards to mutable
containers. Given an immutable container/type, such as a number or
Str or Seq, both will always return true if the values are the same.
With a mutable container, such as an Array, only eqv will return true
if the value is the same, and === will return false for 2 containers
having the same value.
The difference between === and eqv is that, if you have 2 symbols, $a
and $b, and $a === $b returns true, then that result is guaranteed to
be eternal if you don't assign to either symbol afterwards. For a
mutable type like an Array, === returns false on 2 containers because
it can't guarantee that someone else holding another symbol for
either container won't change its content, and so $a or $b could
change after we made the === test, without us causing that to happen,
and so for mutable types, === only returns true for 2 aliases,
because that is the most it can guarantee that they will be the same.
By contrast, eqv does not make the eternal guarantee, and works only
on snapshots, so eqv can safely deep-compare mutable types like
Arrays, since even if one of them changes afterwards, it doesn't
matter, since eqv only guaranteed them equal for that point in time
when it executed.
So do you mean that this code
$a = "One";
$b = "One";
$aa := $a;
say "Same before" if $a === $b;
$aa = "Two";
say "Same after" if $a === $b;
because here I have "2 symbols, $a and $b, and $a === $b returns true"
and I don't assign to either symbol afterwards - and you seem to be
saying that only with mutable types like Array can you change the
contents via another symbol ($aa here).
But according to S03 this would only print "Same before", because the
assigment to $aa would change $a
A new form of assignment is present in Perl 6, called binding, used in
place of typeglob assignment. It is performed with the := operator.
Instead of replacing the value in a container like normal assignment,
it replaces the container itself. For instance:
my $x = 'Just Another';
my $y := $x;
$y = 'Perl Hacker';
After this, both $x and $y contain the string "Perl Hacker", since
they are really just two different names for the same variable.