On 7/3/05, Andrew Pimlott <[EMAIL PROTECTED]> wrote: > 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.
Im not clear here exactly what you are arguing. The code does a reference comparison, it doesnt matter if it burries it in a subroutine or not. >Would using > > my $s = sub { $a->[0] = 1; $_[0]; } > > above also be "looking at refaddrs"? No. But it wouldnt be symmetric would it? You're comparing apples and pan-galactic gargle blasters. > 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. Well, so far you have proposed examples which to me all involve asymmetic operations on the data structure (Assuming i understood properly). Since neither Fergal nor I have taken a position as to what should occur when different operations are performed on the two structures I dont see that its relevent. > 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"? No, but its still an asymmetic operation. If $s access $a AND $b and does the SAME thing to them then if $a and $b were isomorphic to being with they will remain isomorphic afterwards. Also, with complex data structures you basically never are dealing with globals by symbolic reference (or symbol table lookup) as they are all stored by reference. A possible exception to this would be when you are dealing with globrefs. > 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. Actually from the semantics of the language you are dealing with a reference not a global. our $x=1; my $ref=\$x; its not possible to determine that $ref is to a scalar held in the global symbol table without actually doing a traversal of the table and comparing it against everything in the table. I mean dont forget about: my $x=1; *x=\$x; so which is $x? a lexical or a global? > > 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. Or when the structure gets swapped out and then reloaded into different memory locations. Maybe something that we dont have to deal with in perl directly but a related phenomena. > 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. Id like to see an explanation for this assertion. > You're putting unrealistic and informally specified conditions on the > "interchangeability" of the two structures. Hmm. I dont this the conditions are unrealistic. I cant decide about the infomality of the conditions of interchangability tho. > 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. Do you think this is the way is_deeply() behaves? Its not actually. > > All I'm saying is, drop the pretense that this other comparison is > better according to some higher theoretical principle. Well i wont drop the pretense. I say its better because it contains less room for inconsistancy. I say its better because rudimentary secondary tests will often show two objects that is_deeply() considers the same to be obviously different. The comparison we are talking about should never do that. A little example come up in my testing of Test::Struct: my $foo='foo'; deep_eq('foo',$foo); failed. At first i was surprised, then i remembered that one of the properties being checked is if elements are similarly readonly(). I say that there are situations where such a test is very valuable. > > 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. I dont think you've demonstrated that at all. yves -- perl -Mre=debug -e "/just|another|perl|hacker/"