Created
February 2, 2014 07:05
-
-
Save raydiak/8764032 to your computer and use it in GitHub Desktop.
fake 2D subscripts "is rw" problem
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
#!/usr/bin/env perl6 | |
class Matrix4x4 is Array { | |
method at_pos ($i) is rw { | |
self.Array::[$_, $_+1, $_+2, $_+3] given $i * 4 | |
} | |
method perl () { | |
self.defined ?? | |
$?CLASS.perl ~ '.new(' ~ "\n" ~ | |
(^4).map({ | |
self[$_].map({.perl}).join(', ') | |
}).join(",\n").indent(4) ~ | |
"\n)" | |
!! | |
'Matrix4x4' | |
} | |
} | |
my $m = Matrix4x4.new: |@(^16); | |
say 'Before:'; | |
say $m.perl; | |
say "\nChanging value at [1][1] from $m[1][1] to 123"; | |
$m[1][1] = 123; | |
say "\nAfter:"; | |
say $m.perl; # shows no change | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment