develooper Front page | perl.perl6.language | Postings from May 2005

Re: Circular dereference?

Thread Previous | Thread Next
From:
Thomas Sandlaß
Date:
May 4, 2005 08:31
Subject:
Re: Circular dereference?
Message ID:
4278EAA8.8020203@orthogon.com
Autrijus Tang wrote:
> What should this do, if not infinite loop?
> 
>     my ($x, $y); $x = \$y; $y = \$x; $x[0] = 1;

Hmm, after the my both $x and $y store an undef.
Then $x stores a ref to undef. Then $y stores
a ref to ref of undef. I see no circle.

Now let's look at $x = 1. I think it goes down
to the ref and let's it reference the value 1.
This is actually necessary because the ref that $x
"contains" has got other referees---that is the one
stored in $y. Thereafter $y sees the same value 1
through a chain of two references.

"Graphically" this looks as follows:

$y -> ref
          \
$x ------> ref -> 1

So I think even $x = \$x should just do the right thing.
And that is not in any way different from $x = $x + 5.
The RHS is evaluated and the resulting value is stored
in $x.
-- 
TSa (Thomas Sandlaß)


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About