Created
June 27, 2019 19:49
-
-
Save treyharris/d65d2ca0d9459aaeaecadc0b2503bb21 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
#!/usr/bin/env perl6 | |
# Stolen from https://docs.perl6.org/language/functions#sub_nextwith | |
# and annotated with line numbers | |
proto a(|) {*} | |
multi a(Any $x) { | |
say "Any $x"; | |
say "This is Any L$?LINE"; | |
unless $x { | |
die "ouch"; | |
} | |
return 5; | |
} | |
multi a(Int $x) { | |
say "Int $x"; | |
say "This is Int L$?LINE"; | |
nextwith($x + 1); | |
say "never executed because nextsame doesn't return"; | |
} | |
a(-1); | |
# OUTPUT: | |
# Int -1 | |
# This is Int L18 | |
# Any 0 | |
# This is Any L10 | |
# ouch | |
# in sub a at /tmp/stack-replacement line 12 | |
# in sub a at /tmp/stack-replacement line 19 | |
# in block <unit> at /tmp/stack-replacement line 23 | |
# | |
## If nextwith were stack-replacing, we should only get two lines of | |
## backtrace, not three |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment