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 26, 2007 03:30
Subject:
Re: Differences between state variables and smart matches in 5.10 and 6
Message ID:
b77c1dce0703260330p7e928acfm9dd89f99dcaf4fcd@mail.gmail.com
On 26/03/07, Nicholas Clark <nick@ccl4.org> wrote:
> Assuming the same opcode layout.
>
> Currently the execution order for state $a = $b is
>
> $b
> $a
> =
>
> isn't it?
>
> If, instead, assignments where the entire LHS is state variables compiled to
>
> state check on $a:
>   $b
>   $a
>   =
>
> then the RHS would only be evaluated if $a needed assigning to, and also the
> assign op wouldn't need the flags any more.

That's an interesting idea, although it needs a new op "state check"
and heavy manipulation of the optree in the ck_ routines.

But looking at the ops at this way, I just found a new bug :

$ 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)

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