Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #73792] [BUG] 'state' vars in role bodies not supported in Rakudo

2 views
Skip to first unread message

Carl Mäsak

unread,
Mar 24, 2010, 11:36:38 AM3/24/10
to bugs-bi...@rt.perl.org
# 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

Will Coleda via RT

unread,
Jan 10, 2012, 8:01:28 PM1/10/12
to perl6-c...@perl.org
On Wed Mar 24 08:36:38 2010, masak wrote:
> <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 [...]

This now says:

20:00 < [Coke]> rakudo: role A[::T] { state $foo; say ++$foo }; A[Int]; A[Str]
20:00 <+p6eval> rakudo 38165a: ( no output )

Based on TimToday's comments below, is this closable?
--
Will "Coke" Coleda

Carl Mäsak via RT

unread,
Jan 11, 2012, 5:06:10 AM1/11/12
to perl6-c...@perl.org
On Tue Jan 10 17:01:28 2012, coke wrote:
> On Wed Mar 24 08:36:38 2010, masak wrote:
> > <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 [...]
>
> This now says:
>
> 20:00 < [Coke]> rakudo: role A[::T] { state $foo; say ++$foo };
> A[Int]; A[Str]
> 20:00 <+p6eval> rakudo 38165a: ( no output )
>
> Based on TimToday's comments below, is this closable?

Based on the ticket name, TimToday's comment, and the fact that Rakudo
no longer produces an error, I'd say this is closable. Marking
"resolved".
0 new messages