: On Thu, 2005-03-31 at 23:46 -0800, Darren Duncan wrote:
On Fri, Apr 01, 2005 at 08:04:22AM -0500, Aaron Sherman wrote:
:
: > What I want to be able to do is compare two references to see if they
: > point to the same thing, in this case an object, but in other cases
: > perhaps some other type of thing.
:
: Let's be clear about the difference between P5 and P6 here. In P5, an
: object was actually a reference with special magic that indicated that
: it was also tied to a package.
:
: In P6, an object is a data-type. It's not a reference, and any member
: payload is attached directly to the variable.
Well, it's still a reference, but we try to smudge the distinction in P6.
: So, comparing references to objects isn't all that common in P6, though
: it could certainly happen.
:
: Now, back to the concept of identity comparison... I would expect that
: you could do this:
:
: $ref1 ~~ $ref2
No, ~~ will deref any explicit references and smart match against
what is referenced. That's part of the intentional smudging.
: The table in S4 doesn't have an entry for "Any ~~ Reference", but my
: guess is that that's just an oversight, as it seems to fit into the flow
: nicely.
That would be going back to the P5 way of thinking. The ~~ operator
doesn't try to guess whether the user meant references to refer to
themselves or their referent. It always assumes the referent. Note
that when you say
@foo ~~ @bar
it's actually passing two array references to ~~, for instance, since
they're in scalar context.
: More generally, I see no direct way to tell if two values have the same
: storage (the same PMC in Parrot), so you might have to do something
: P5ish:
:
: \$a ~~ \$b
Wouldn't work. Ends up doing the same as $a ~~ $b.
Anyway, that's what =:= is there for.
Larry