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

Re: not a reference - What does this mean?

Thread Previous
From:
Jonathan Worthington
Date:
May 4, 2008 16:18
Subject:
Re: not a reference - What does this mean?
John M. Dlugosz wrote:
> Perl 6 doesn't have references anymore, it has captures.  So, what 
> does the following mean:
>
> @x = <foo bar>;
> $a = [1, 2, \@x];
>
> I imagine that the 3rd element of the Array is itself an Array, and is 
> the same object that is bound to @x.  But captures are lazy 
> context-sensitive beasts, so I wonder if there is more poised to go on 
> than I want or care about in this example.
>
>  say $a[2] === @x;     #gives True
>  @x[1] = "baz";
>  say $a[2][1];  #gives baz
Captures themselves are immutable, but the underlying data that they 
reference is not. Thus the laziness, or at least that's what I 
understand it to mean. I'm sure I read something along these lines in a 
synopsis, probably S02.

Jonathan


Thread Previous


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About