Skip to content

Instantly share code, notes, and snippets.

@araraloren
Created January 19, 2017 15:47
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 araraloren/19bc439c6fba86f7ca3b86418766204e to your computer and use it in GitHub Desktop.
Save araraloren/19bc439c6fba86f7ca3b86418766204e to your computer and use it in GitHub Desktop.
slice for perl6
#!/usr/bin/env perl6
class SliceThing {
has $.f;
has $.t;
}
sub infix:<<':'>>(Int $f, Int $t) {
return SliceThing.new(f => $f, t => $t);
}
multi sub postcircumfix:<<'[ ]'>>(Str $str, SliceThing $st) {
return $str.substr($st.f, $st.t - $st.f + 1)
}
say "123"[1 : 2];
# run test -> http://ideone.com/ZzVu7W
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment