Created
May 1, 2016 12:25
-
-
Save usev6/65701798270ef412a1e41b8c480a0133 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm trying to debug the following NullPointerException: | |
$ perl6-j -e 'CallFrame.new.perl' | |
java.lang.NullPointerException | |
in block <unit> at -e line 1 | |
For some reasons iterating over the values of a specially constructed Stash (using nqp::iterval) does not work. I get the following output with the program below. | |
$ perl6-m iterating.p6 # works fine | |
-- Iterating using $h.values -- | |
([] (!UNIT_MARKER) (EXPORT) (Any) Nil (GLOBAL) (GLOBAL) Nil (Mu) (Mu) Nil <anon> (GLOBAL)) | |
-- Iterating using $h.foo -- | |
([] (!UNIT_MARKER) (EXPORT) (Any) Nil (GLOBAL) (GLOBAL) Nil (Mu) (Mu) Nil <anon> (GLOBAL)) | |
-- Iterating "by hand" -- | |
[] (!UNIT_MARKER) (EXPORT) (Any) Nil (GLOBAL) (GLOBAL) Nil (Mu) (Mu) Nil <anon> (GLOBAL) | |
$ perl6-j iterating.p6 | |
-- Iterating using $h.values -- | |
((Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu)) | |
-- Iterating using $h.foo -- | |
((Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu) (Mu)) | |
-- Iterating "by hand" -- | |
(Mu) (GLOBAL) <anon> (!UNIT_MARKER) Nil (Mu) Nil (GLOBAL) (EXPORT) Nil [] (Any) (GLOBAL) | |
==== | |
$ cat iterating.p6 | |
use nqp; | |
use MONKEY-TYPING; | |
my Mu $ctx := nqp::ctx(); | |
my $h := nqp::create(Stash); | |
nqp::bindattr($h, Map, "\$!storage", $ctx); | |
#say $h.keys; # works | |
#say $h.values; # all (Mu) on JVM | |
#say $h.pairs; # NPE on JVM | |
augment class Stash { | |
# duplicate method 'value' from Map.pm | |
method foo () { | |
Seq.new(class :: does Rakudo::Internals::MappyIterator { | |
method pull-one() { | |
$!iter | |
?? nqp::iterval(nqp::shift($!iter)) | |
!! IterationEnd | |
} | |
method push-all($target) { | |
my $no-sink; | |
$no-sink := | |
$target.push(nqp::iterval(nqp::shift($!iter))) | |
while $!iter; | |
IterationEnd | |
} | |
}.new(self)) | |
} | |
} | |
say "-- Iterating using \$h.values --"; | |
say $h.values; | |
say "-- Iterating using \$h.foo --"; | |
say $h.foo; | |
say '-- Iterating "by hand" --'; | |
for $h.keys -> $key { print $h{$key}.gist, " " }; |
Author
usev6
commented
May 1, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment