Skip to content

Instantly share code, notes, and snippets.

@timo
Last active December 18, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timo/5841141 to your computer and use it in GitHub Desktop.
Save timo/5841141 to your computer and use it in GitHub Desktop.
trying to implement multidimensional slicing
class Foo is Array {
multi method postcircumfix:<[ ]>(\SELF: LoL $coords) is rw {
my $subcoords = $coords[1..^*].lol;
if +@$subcoords == 1 {
$subcoords = $subcoords[0].list;
}
for $coords[0].list {
SELF[$_][@$subcoords];
}
}
}
my $farr = Foo.new();
for (0..7) X (0..7) -> $x, $y { $farr[$x][$y] = $x ~ $y }
say $farr[1, 2; 3, 4].perl;
say $farr[0, 1; 1, 4].perl;
$farr[1, 2; 5, 6] = <foo bar>, <baz quux>;
say $farr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment