Skip to content

Instantly share code, notes, and snippets.

@treyharris
Created June 27, 2019 19:49
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 treyharris/d65d2ca0d9459aaeaecadc0b2503bb21 to your computer and use it in GitHub Desktop.
Save treyharris/d65d2ca0d9459aaeaecadc0b2503bb21 to your computer and use it in GitHub Desktop.
#!/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