On Sun, Jul 03, 2005 at 12:32:01PM +0100, Fergal Daly wrote:
> On 7/3/05, Andrew Pimlott <[EMAIL PROTECTED]> wrote:
> > How about
> > 
> >     my $a = [];
> >     my $b = [];
> >     my $s = sub { $_[0] == $a; }
> >     is_deeply($a, $b);              # passes
> >     is_deeply($s->($a), $s->($b));  # fails
> 
> Near the top of the last mail I said "there is nothing you can do to
> tell them apart (except actually looking at refaddrs)" which is
> bascially what you've done here.

I find that to be an unreasonable standard.  Using a captured variable
in a closure is just like using any other variable, as far as the
programmer is concerned.  Would using

    my $s = sub { $a->[0] = 1; $_[0]; }

above also be "looking at refaddrs"?  In that case, you might as well
say that any use of references is cheating, which limits you to a pretty
unuseful subset of perl.

Further, consider my example, except using globals $a, $b, $s instead of
lexical.  Now, $s accesses $a through the symbol table.  Is that also
"looking at refaddrs"?  Sure, implementation-wise you're going through a
reference, but as far as the semantics of the language are concerned,
you're just accessing a global variable.  It makes very little sense to
call that cheating.

> Again it comes down to my thinking of these 2 structures as 2 separate
> things maybe even on 2 separate computers (or produced by 2 differrent
> programs - perhaps before and after a change) and you want to know
> whether they have produced answers which are completely
> interchangeable. When you think in those terms, comparing addresses
> from one structure to those in the other makes no sense.

You would have to go further and say that the two structures are the
"only things" on those two computers, or that they are entangled with
other data (including the symbol table!) in the "same" ways.  You're
putting unrealistic and informally specified conditions on the
"interchangeability" of the two structures.

Which is not to say that this sense of equality is not useful, or that
you shouldn't document it in terms of these unrealistic and informally
specified conditions.  Indeed, I could do the same thing with the
current is_deeply behavior:

    Two structures are considered to be the same if you could not
    observe the difference without using a) finding the address of a
    reference, b) reference comparison, or c) variable assignment.

All I'm saying is, drop the pretense that this other comparison is
better according to some higher theoretical principle.  When it comes
down to it, not a lot of higher theoretical principles apply to Perl
anyway. ;-)

> You can say I'm moving the goal posts but if you allow comparisons
> like that, the whole concept is trivially broken

My whole point is that all the notions of equality we're discussing
_are_ trivially broken, and we shouldn't pretend they're not.  Again,
they're still useful.  The only notion that's not trivially broken is is
that references are the same only if they refer to the same object; but
that's not usually useful.

Andrew

Reply via email to