I really want to reply here, but I am having a hard time thinking of a good example. It's not that I wouldn't use state, but that I would use it so often and instinctively that I can't really come up with anything of note. It would be like asking me for a "good example" of using the assignment operator. It's the kind of subconscious thing where I just use it when I need it.
That said, you [update: and mirod -- I must have missed his reply] already described the general circumstances when I would use state. Basically, any time I would reach for a bare-block-scoped lexical to create a closure. So instead of the Perl5esque:
{ my $foo; sub foo { $foo += @_; } }
I'd use:
sub foo { state $foo; $foo += @_; }
Which -- while maybe not a big win -- I think is pretty nice.
Update: BUU makes a good point.
In reply to Re: How will you use state declared variables in Perl6?
by revdiablo
in thread How will you use state declared variables in Perl6?
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |