develooper Front page | perl.perl5.porters | Postings from March 2007

Re: Differences between state variables and smart matches in 5.10 and 6

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
March 27, 2007 03:01
Subject:
Re: Differences between state variables and smart matches in 5.10 and 6
Message ID:
b77c1dce0703270301x33be8480l4962fdcac269eabc@mail.gmail.com
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


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