3 # 2006-12-19 (rough) update to current spec
5 my subset HQ9PlusProgram
11 where
{ .chars
== 1 };
13 my subset Error
::OutOfBounds of Failure where True
;
15 has HQ9PlusProgram
$.program
;
16 has Int
$.accumulator
= 0;
17 has Int
$position = 0; # twigilless are private
20 'h' => { self
.hello
},
21 'q' => { self
.quine
},
27 # Java, anyone? Feel free to fix this.
31 when Error
::OutOfBounds
{
32 return; # end of program
40 given $.program
.substr($position++, 1) {
45 my method hello
() { say "Hello, world!" }
46 my method quine
() { say $.program
}
47 my method plus
() { $.accumulator
++ }
53 $i bottles of beer on the wall
55 Take one down
, pass it around
58 say "$i bottles of beer on the wall!"
65 HQ9Plus - A HQ9+ implementation
69 HQ9Plus.new(program => $foo).run;
71 my $program = HQ9Plus.new(program => $foo);
75 ...inspect the program state...
80 C<HQ9Plus> implements a I<HQ9+> interpreter with stepping.
84 http://en.wikipedia.org/wiki/HQ9+
88 Ilmari Vacklin <ilmari.vacklin@helsinki.fi>