Matthijs van Duin <[EMAIL PROTECTED]> writes:

> On Sat, Mar 22, 2003 at 10:24:09PM +0200, arcadi shehter wrote:
>>  sub a {
>>      state $x;
>>      my $y;
>>      my sub b { state $z ; return $x++ + $y++ + $z++ ; }
>>      return &b;   # is a \ before &b needed?
>>  }
>>
>>
>>will all &b refer to  the same $z ?
>
> yes, they will

Are you sure about that. If state is declaring a lexically scoped
alias to a property of the block/sub, then each invocation of a will
generate a different block/sub &b, which implies that the various &b
instances won't share the same $z property.

>> does it mean that this is legitimate  sub a {
>>      state $x;
>>      my $y;
>>      state sub b { state $z ; return $x++ + $y++ + $z++ ; }
>>      return &b;   # is a \ before &b needed?
>>  }
>
> No, since you can't refer to $y in that sub (perl 5 actually allows
> you to do that but gives a warning 'Variable "%s" will not stay
> shared' - but I hope perl 6 will simply give a compile-time error)

Personally I would hope that it would correctly close over
$y. Especially if, as you claim, $z would be shared by all values of
&b. Otherwise there's no way to get that particular behaviour. 

-- 
Piers

Reply via email to