# New Ticket Created by "Carl Mäsak" # Please include the string: [perl #73792] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=73792 >
<ash_> what would a state variable in a class definition be like? <masak> ash_: like this? class A { state $foo } <ash_> yeah <masak> ash_: it wouldn't really make practical sense, because the class block is only run once. <masak> (AFAIK) <jnthn> What does a state variable gain over a lexical in a class body? <jnthn> Unless it's an anonymous class... :-) <jnthn> In a role it'd be really funky though. :-) <masak> hm :) <jnthn> role Foo[::T] { ... } # body may be run many times. <masak> rakudo: role A[::T] { state $foo; say ++$foo }; A[Int]; A[Str] <p6eval> rakudo db0f85: OUTPUT«Symbol '$foo' not predeclared in !class_init_12 [...] <masak> aww :) * masak submits rakudobug <jnthn> masak: state nyi in Rakudo <jnthn> (master) <masak> oh. <jnthn> well <jnthn> file ticket anyway <masak> alpha: role A[::T] { state $foo; say ++$foo }; A[Int]; A[Str] <p6eval> alpha 30e0ed: ( no output ) <jnthn> There's no promise it'll just work right off. <TimToady> if you want multiple state vars in role, that probably means there's a missing clone <TimToady> since cloning dups state vars <masak> TimToady: what would the above code print? 1\n2\n, right? <ash_> well, in that case, my thoughts wouldn't work right, if state is cloned <TimToady> masak: it doesn't print anything in my head before I've had my coffee <masak> TimToady: :) <TimToady> I'm just saying that *if* role clones its block on instantiation, you'd get 1,1 <masak> nod. <TimToady> but if you had state $.foo, it'd presumably put an accessor to each 1 <masak> right now it prints nothing, even in alpha, so it's definitely a bug :) <TimToady> my brane is NYI today