Created
January 19, 2017 15:47
-
-
Save araraloren/19bc439c6fba86f7ca3b86418766204e to your computer and use it in GitHub Desktop.
slice for perl6
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 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