John Williams wrote:
>On Tue, 1 Apr 2003, Michael Lazzaro wrote:
>> So I *really* don't think comparing the equality of references will be
>> a good idea, in P6.
<snip>
> The main point is that the
> reference is a unique identifier for an object.  At least, I haven't been
> able to think why it wouldn't be yet (barring persistence).

Yes, I believe that to be true as well.  For all practical purposes, the
memory address of an object is a unique identifier for the object, since
only one object can exist at the same point in memory.  Well, probably.  :-)

> So if you cede that point, achieving your identity comparison is a trivial
> matter of spelling the comparison correctly.
> Maybe its "$x.ref == $y.ref", since 'ref' is less common than 'id'.
> Maybe its something else.

Yes.  I expect that internally, that's how it will work.  (And agreed,
C<.ref> is probably a good name.)

My concern with explicitly comparing refs in order to compare identity
is a philosophical one.  It may be perfectly acceptable to do it via

    $x.ref == $y.ref;    # do they exist at the same location?

but I worry that that is a bit obtuse.  I'd rather people didn't have to
worry about comparing reference locations, even indirectly, because it
leads to thinking you can do things like this:

    my $loc = $x.ref;
    ...stuff...
    $loc == $y.ref;    # OOPS: but has $x moved since then?

Depending on the implementation, code like that might be dangerous.

In addition to discouraging the above behavior, the main reason I like
an operator-based solution is that it can be used to test
identity-equality in a very explicit way.  You're not testing whether
two objects "exist at the same location" -- you're testing whether two
objects "share the same identity".  In practice, those two concepts are
linked, but conceptually I'd rather teach people to think of it as the latter.

I like the suggestion of =:= in particular because it so clearly relates
to "bound to", so it feels quite elegant.

MikeL

Reply via email to