On 7/4/05, Andrew Pimlott <[EMAIL PROTECTED]> wrote: > On Mon, Jul 04, 2005 at 12:36:29AM +0200, demerphq wrote: > > On 7/3/05, Andrew Pimlott <[EMAIL PROTECTED]> wrote: > > >Would using > > > > > > my $s = sub { $a->[0] = 1; $_[0]; } > > > > > > above also be "looking at refaddrs"? > > > > No. But it wouldnt be symmetric would it? > > It's no less symmetric that the first example. In fact, I would say > it's symmetric. I'm calling the same code on each. What is your > definition? I would guess your definition is either circular, or would > restrict one to an unrealistically small subset of Perl. In the real > world, code like the above is perfectly normal.
There's an easy way to see what's "accptable" and what's not and what exactly this level equality means. Consider the following code template: ####### # lots of stuff doing anything you like including # setting global variables my $value = do { # these can access any globals etc my $a = one_way(); my $b = another_way(); is_very_deeply($a, $b) || die "they're distinuguishable"; # choose one of $a and $b at random rand(2) < 1 ? $a : $b; }; print test($value); ####### Assuming: 1 nothing looks at ref addrs (they may compare refs addrs, they can even store them in variables for comparison later on as long as nothing depnds on the actual value, just it's value in comparison to other ref addrs). 2 - one_way() and another_way() don't have side effects *** Then test() cannot tell whether it got $a or $b. That is, any attempt by one_way() or another_way() to communicate with test() will be caught by is_very_deeply(). In this case it's clear that sub test { $_[0] == $a } is not acceptable because only one of $a and $b ever makes it back into program flow and at that point it's got a new name. If you think this situation is contrived, it is. The point is to try to clarify which operations are legal and which aren't and why. This test isn't supposed to be used in day to day programming. It's for use in test scripts to make sure that 2 different ways of constucting something agree to the greatest degree possible given and in test scripts you should control the environment as much as possible so contrived isn't really such a problem. > Again, your form of equality is perfectly good, but it's not privileged > over any other. Both your equality and is_deeply are belied by totally > normal, plausible code. That's all I wanted to point out. It's privileged in that it's the strictest possible form of equality that doesn't require ref addr comparison. That is, if this one says yes then so will any other. It's privileged because it's the only test that works in the code above, if you replace is_very_deeply with any other less strict form of equality you can easily concoct a one_way(), another_way() and test() that can detect which of $a or $b was selected. F *** If you think this is too restrictive then you can rewrite this with fork() or threads, an is_very_deeply that is able to see into both processes and get rid of the rand. You also have to pass all the side-effected variables into is_very_deeply too.