On Tue, 1 Apr 2003, Michael Lazzaro wrote:So I would imagine it _is_ possible to test that two values "have the
same identity", but I would imagine it is -not- possible to actually
get what that identity "is". There's no .id method, per se, unless you
create one yourself.
What about the \ (reference) operator? If you take two references to an
object, they should compare the same, right?
In theory, I would think so. But in P6 practice, that might not be as useful as it sounds:
my @a; my @b := @a; # bind @b same as @a
[EMAIL PROTECTED] == [EMAIL PROTECTED]; # true, but not for the reason you think! @a =:= @b; # true, are bound to the same array
Note if we are truly strict about C<==> always meaning "compare numerically", I imagine that the line:
[EMAIL PROTECTED] == [EMAIL PROTECTED];
would in fact be identical to _this_ line:
@a.length == @b.length; # or whatever it's called
or even just:
@a == @b;
...which is probably not at all what you meant when you tried to compare [EMAIL PROTECTED] == [EMAIL PROTECTED]
Likewise, if you attempt to store the numerified reference of something, in hopes of using it later as an identifier:
my num $id = [EMAIL PROTECTED];
You would be in for a world of hurt. That line would actually set $id to the number of elements in @a -- at least, I hope it would:
my $x = @a; # stores a reference to @a my $x = [EMAIL PROTECTED]; # same thing my int $x = @a; # stores length of @a my int $x = [EMAIL PROTECTED]; # same thing
So I don't think comparing references would do what you wanted, for arbitrary (non-scalar) objects. Or rather, I don't think it'll be easy to get at a "numeric representation" of a reference ... a true 'identity' test might be a better approach.[*]
(?)
MikeL
[*] (Also, any identity test that relies on numerification or other transformation of the comparators is doing a lot of unnecessary work.)