Who has the best state implementation? (For some arbitrary definition of "best".) Let's see:
$ cat state.pl
sub foo {
state $bar = "Pie";
say $bar;
$bar = "Good";
}
foo();
foo();
$
./parrot languages/perl6/perl6.pbc state.pl
scope declarator 'state' not implemented at line 2, near "= \"Pie\";\n "
current instr.: 'parrot;PGE::Util;die' pc 120 (runtime/parrot/library/PGE/Util.pir:82)
called from Sub 'parrot;Perl6;Grammar;Actions;_block1900' pc 107647 (src/gen_actions.pir:5109)
called from Sub 'parrot;Perl6;Grammar;Actions;_block1890' pc 107410 (src/gen_actions.pir:5015)
called from Sub 'parrot;Perl6;Grammar;Actions;_block1864' pc 107316 (src/gen_actions.pir:4975)
called from Sub 'parrot;Perl6;Grammar;Actions;scope_declarator' pc 105807 (src/gen_actions.pir:4402)
called from Sub 'parrot;Perl6::Grammar;scope_declarator' pc 73809 (src/gen_grammar.pir:22436)
called from Sub 'parrot;Perl6::Grammar;noun' pc 66663 (src/gen_grammar.pir:19982)
called from Sub 'parrot;Perl6::Grammar;term' pc 62462 (src/gen_grammar.pir:18460)
called from Sub 'parrot;PGE::OPTable;parse' pc 1998 (compilers/pge/PGE/OPTable.pir:532)
called from Sub 'parrot;Perl6::Grammar;statement' pc 18468 (src/gen_grammar.pir:3117)
called from Sub 'parrot;Perl6::Grammar;statementlist' pc 15720 (src/gen_grammar.pir:2170)
called from Sub 'parrot;Perl6::Grammar;statement_block' pc 13578 (src/gen_grammar.pir:1384)
called from Sub 'parrot;Perl6::Grammar;block' pc 14687 (src/gen_grammar.pir:1795)
called from Sub 'parrot;Perl6::Grammar;routine_def' pc 48620 (src/gen_grammar.pir:13549)
called from Sub 'parrot;Perl6::Grammar;routine_declarator' pc 47075 (src/gen_grammar.pir:13013)
called from Sub 'parrot;Perl6::Grammar;noun' pc 66887 (src/gen_grammar.pir:20052)
called from Sub 'parrot;Perl6::Grammar;term' pc 62462 (src/gen_grammar.pir:18460)
called from Sub 'parrot;PGE::OPTable;parse' pc 1998 (compilers/pge/PGE/OPTable.pir:532)
called from Sub 'parrot;Perl6::Grammar;statement' pc 18468 (src/gen_grammar.pir:3117)
called from Sub 'parrot;Perl6::Grammar;statementlist' pc 15720 (src/gen_grammar.pir:2170)
called from Sub 'parrot;Perl6::Grammar;statement_block' pc 13578 (src/gen_grammar.pir:1384)
called from Sub 'parrot;Perl6::Grammar;TOP' pc 10420 (src/gen_grammar.pir:204)
called from Sub 'parrot;PCT::HLLCompiler;parse' pc 564 (src/PCT/HLLCompiler.pir:348)
called from Sub 'parrot;PCT::HLLCompiler;compile' pc 440 (src/PCT/HLLCompiler.pir:291)
called from Sub 'parrot;PCT::HLLCompiler;eval' pc 755 (src/PCT/HLLCompiler.pir:450)
called from Sub 'parrot;PCT::HLLCompiler;evalfiles' pc 1067 (src/PCT/HLLCompiler.pir:587)
called from Sub 'parrot;PCT::HLLCompiler;command_line' pc 1246 (src/PCT/HLLCompiler.pir:676)
called from Sub 'parrot;Perl6::Compiler;main' pc 8860 (perl6.pir:183)
$
./pugs state.pl
Pie
Pie
$
/usr/local/perl-5.10.0/bin/perl -Mfeature=:5.10 state.pl
Pie
Good
Yes, strange as it may seem, Perl 5 has the most complete implementation of Perl 6's state†. Only Perl 5 performs an initialisation via = once. I blame Rafael, Dave and me.
† At least this week. For some value of this week. Until someone reads this Perl blog and gets hacking.
Odd - Pug's state worked correctly back in 2005 (Score:1)
Re: (Score:2)
I don't think that it did. Certainly, that example is not a good enough test, because it makes all three calls to
gen_cashierbefore it uses any of the closures, so it makes no difference how many times that assignment of0is performed. If I re-write it like thisRakudo now works (Score:1)
Yet Another Just another perl hacker,