On 8/15/06, Darren Duncan wrote:
At 2:51 PM -0600 8/15/06, David Green wrote:
[...]
You are right, but we have both Seq and Array types, so depending which one you use, you want either the === or eqv operators to do what you want. There is no reason that === should say 2 Array are equal; we have eqv for that, or use 2 Seq instead of 2 Array if you want === to return true on the same values.


Is Seq vs Array the right distinction here? A Seq is immutable, so I can't change its size, for instance, which is not what I want. I just want [1,2] to be === to [1,2], or [1,2, [EMAIL PROTECTED] to be equal to [1,2, [EMAIL PROTECTED] but !=== [1,2, [EMAIL PROTECTED] -- eqv won't work in the latter case (regardless of Seq vs. Array -- I didn't think it made a difference here).

Actually, my previous example which Larry said was correct was:

   $a=[1, 2, [EMAIL PROTECTED];
   $c=[1, 2, [EMAIL PROTECTED];
   $d=[1, 2, [EMAIL PROTECTED];

        $a =:= $c;      #false, different variables
        $a === $c;      #true, same elements make up $a and $c
        $a eqv $c;      #true, same elements therefore same values

        $a === $d;      #false, [EMAIL PROTECTED] and [EMAIL PROTECTED] are 
different refs

So $a, $c, and $d may all have the same *value* (or "snapshot", when evaluated all the way down through nesting and references), i.e. they might be eqv, but only $a and $c are === because they have the same contents [unevaluated contents] and $d doesn't.

Which is what makes sense to me, but S03 says "[1,2]!===[1,2]". My position is that even if they are different "objects", that difference is fairly useless, and should therefore be hidden (same as it is for objects that are strings).

First of all, in Perl 6, there are no separate "arrays" and "array refs"; we simply have the 'Array' type, which is treated as a lump on its own.
More generally, there are no "reference" types in Perl 6.

I thought there were, just not as conspicuously. There are "captures" anyway, which are supposed to be like P5-refs, and beyond. (However, I admit to being a bit fuzzy on exactly how Signatures and Captures work -- if anyone could write an Exegesis on the subject, I know I'm not the only one who would appreciate it.)

[...]
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.

So, given mutable types, $a===$b if and only if $a=:=$b? That doesn't sound right, otherwise === seems superfluous. The thing is if $a=[1,2] and $b=[1,2], then arrays or not, nothing can change $a or $b except by changing $a or $b. [Or aliases bound to same, of course.] So there's no reason for $a===$b to be false. (If they look the same, and they act the same, then they're ducks. Er, or something.)

(Hoping the 'eternal' stuff hasn't thrown me off and resulted in my completely misinterpreting what you were trying to say.)


-David

Reply via email to