»ö« #raku and #raku-dev are OPEN FOR BUSINESS | perl6.org/ | evalbot usage: 'p6: say 3;' or /msg camelia p6: ... | irclog: irc.perl6.org or colabti.org/irclogger/irclogger_log/perl6 | UTF-8 is our friend! 🦋
Set by mst on 15 October 2019.
user3 p6: say %(1=>(2,3)).values.flat 13:11
evalable6 ((2 3))
user3 why doesn't that flatten 13:12
user3 p6: sub s { { state $i++; } }; put s; put s 13:13
evalable6 0
0
user3 why is "state" ignored?
jnthn Because state works per closure, and your {...} is a closure, cloned at returned from the sub 13:14
user3 ok, so it's not like C static
jnthn m: sub s { { state $i++ } }; my $s1 = s; say $s1(); say $s1();
evalable6 (exit code 1) No such method 'CALL-ME' for invocant of type 'Int'
in block <unit> at /tmp/biYAZpiPis line 1
jnthn No 13:15
Ah, though...it's a bare block there so less useful :)
m: sub s { return { state $i++ } }; my $s1 = s; say $s1(); say $s1();
evalable6 0
1
jnthn That's what I wanted to show
m: sub s { return { state $i++ } }; my $s1 = s; my $s2 = s; say $s1(); say $s2(); say $s1(); say $s2();
evalable6 0
0
1
1
jnthn That's why you can use `state` in a `for` loop and it's just scoped to that iteration 13:16