On Mon, Mar 24, 2003 at 03:23:21PM +0000, Piers Cawley wrote:
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.

I've been thinking about it, but it depends on semantics. I personally don't think that the behaviour of "state" inside a block should depend on whether or not that block uses lexical variables of the surrounding scope. So I think 'state' should - semantically speaking - be a property of the surrounding lexical block, and therefore be shared amoung all instances of &b in this situation.



     state $x;
     my $y;
     state sub b { state $z ; return $x++ + $y++ + $z++ ; }

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.

it can't close over $y: b is state, so it's the same for each invocation of the sub, while $y is different for each invocation.


if you want b to close of $y, making b state makes no sense... you should use 'my sub b' instead in that case.

--
Matthijs van Duin  --  May the Forth be with you!

Reply via email to