Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Created August 24, 2016 20:34
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 awwaiid/488cb1ef1d1b68eb6f7d86fcd314eaa8 to your computer and use it in GitHub Desktop.
Save awwaiid/488cb1ef1d1b68eb6f7d86fcd314eaa8 to your computer and use it in GitHub Desktop.
> 5+5
10
> next
CONTROL: Died with CX::Next
EXCEPTION: control exception
in sub eval at simple-repl.p6 line 8
in block <unit> at simple-repl.p6 line 34
> last
CONTROL: Died with CX::Last
EXCEPTION: control exception
in sub eval at simple-repl.p6 line 8
in block <unit> at simple-repl.p6 line 34
> return
CONTROL: Died with CX::Return
EXCEPTION: control exception
in sub eval at simple-repl.p6 line 8
in block <unit> at simple-repl.p6 line 34
> die 'hmm'
EXCEPTION: hmm
in block <unit> at EVAL_4 line 1
in sub eval at simple-repl.p6 line 11
in block <unit> at simple-repl.p6 line 34
CONTROL: Died with CX::Next
in block at simple-repl.p6 line 40
in block <unit> at simple-repl.p6 line 21
control exception
in sub eval at simple-repl.p6 line 8
in block <unit> at simple-repl.p6 line 34
use MONKEY-SEE-NO-EVAL;
sub eval($code) {
CONTROL {
say "CONTROL: {$_.gist}";
die "control exception";
}
EVAL $code;
}
my @cmds =
"5+5",
"next",
"last",
"return",
"die 'hmm'";
REPL: loop {
print "> ";
# Normally this reads from STDIN, here read from list for test
# my $code = get;
my $code = shift @cmds;
say $code;
# EOF
if !$code.defined {
last REPL;
}
my $result = eval $code;
say $result;
CATCH {
say "EXCEPTION: {$_.gist}";
next REPL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment