On Thu, 3 Apr 2003, mlazzaro wrote:

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

I don't thing there is any danger.  Consider this:

    my $xref = \$x;
    ...stuff...
    print $$xref;    # OOPS: but has $x moved since then?

Obviously that "oops" is not a concern.  The reference is not necessarily
a memory address.  The GC can move objects around if it wants, but it must
make sure the references to an object still refer to the object.

The danger I see with reference comparison involves the perl6
auto-dereferencing, and how to be sure we have a reference-to-an-object
and not a reference-to-a-reference-to-an-object.  For example:

   $b = @a;
   $b.ref;             # is this [EMAIL PROTECTED] or [EMAIL PROTECTED]
   $b.ref == @a.ref;   # will this work?  should this work?

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

Personally, I doubt the necessity of yet-another-operator, because I'm not
convinced the operation is a frequent one.  We may both be biased by
our personal coding experience on that count.  But, no one can stop you
from defining infix:=:= in your own code.

~ John Williams


Reply via email to