On 26/03/07, Abigail <abigail@abigail.be> wrote:
> > $ bleadperl -E 'sub f{say state$x=42;++$x;say $x}f;f'
> > 42
> > 43
> > 42
> > 44
> >
> > The return value of a state assignment is the right hand side. (but
> > the actual assignment happens only once, correctly)
>
>
> It looks like the return value is the right hand side only if there's no
> assignment done - the first time it returns an lvalue:
>
> $ curperl -E 'sub f {(state $x = 42)++; say $x} f; f;'
> 43
> Modification of a read-only value attempted at -e line 1.
I committed a small fix for those as change #30772. That does not
implement Nicholas idea, which would need much more work; but at least
it doesn't leave leftovers on the stack.
Thread Previous
|
Thread Next