develooper Front page | perl.perl5.porters | Postings from October 2012

Re: [perl #114932] state(@a) =

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
October 16, 2012 15:36
Subject:
Re: [perl #114932] state(@a) =
Message ID:
CAHAeAG7E-GuL0FhFigNORDb8ktebzphQ+iT44pt_7m-Z-M+gOw@mail.gmail.com
On Tue, Oct 16, 2012 at 11:45 PM, Father Chrysostomos via RT <
perlbug-comment@perl.org> wrote:

> On Sun Sep 16 12:15:05 2012, sprout wrote:
> > This hasn't been implemented yet, and I do not see any existing ticket
> > for it.
> >
> > (state @a) = ... is not supposed to have the assign-once behaviour.
> >
> > state(@a) = ... and state @a = ... are (if Ι understand correctly).
>
> I believe this reasoning makes sense in Perl 5 (even if it is not
> exactly the same as the Perl 6 explanation):
>
> It is 'state' (with its arguments) that is treated specially on the LHS
> of =.  So (state @a)=... is not special-cased, because what is on the
> LHS is more than just state.  But state(@a) is special-cased, because
> the (@a) bit is part of the state() call.  (Think of state as a function.)
>
> So that means state(our @foo) = ... should assign to the package
> variable @foo once.
>
> Right?


   ... and evaluate the RHS only once (as in the scalar case).  Oh, and as
I was reminded recently, that's "once per subref" - as in the scalar case:

eirik@bluebird[00:31:09]~$ perl -E 'for (1..2) { sub {
eirik@bluebird[00:31:09]~$
perl -E 'for (1..2) { sub { for (1..3) { state $t=warn; say } }->() }'
Warning: something's wrong at -e line 1.
1
2
3
Warning: something's wrong at -e line 1.
1
2
3
eirik@bluebird[00:31:11]~$


  I think "evaluate the RHS only once" means that the RHS is _also_ part of
the state call, but other than that, I think you got it.  Or at least, I
agree. :)


Eirik

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