Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Created October 18, 2015 14: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 awwaiid/f537ccf5d25cf4ad7cf7 to your computer and use it in GitHub Desktop.
Save awwaiid/f537ccf5d25cf4ad7cf7 to your computer and use it in GitHub Desktop.
------------- [List variables] ---------------
my vars: $_ $! @parent_vars $*DISPATCHER @my_vars RETURN $¢ $x $/
caller vars: $y $_ $! $*DISPATCHER RETURN $¢ $x $/
------------- [Eval Variable] ---------------
Local $x=5
EVAL $x=5
EVAL LEXICAL:: $x=5
EVAL CALLER:: $x=2
------------- [EVAL var file/line] ---------------
Local $?FILE/$?LINE:/home/awwaiid/tlt/projects/perl6/lrep/./trystuff.p6:27
EVAL $?FILE/$?LINE:/home/awwaiid/tlt/projects/perl6/lrep/EVAL_3:1
EVAL LEXICAL $?FILE/$?LINE:/home/awwaiid/tlt/projects/perl6/lrep/EVAL_4:1
EVAL CALLER $?FILE/$?LINE:/home/awwaiid/tlt/projects/perl6/lrep/EVAL_5:1
------------- [EVAL callframe file/line] ---------------
Local callframe file/line:./trystuff.p6:33
EVAL callframe file/line:EVAL_6:1
EVAL LEXICAL callframe file/line:EVAL_7:1
EVAL CALLER callframe file/line:EVAL_8:1
------------- [EVAL callframe(1) file/line] ---------------
Local callframe(1) file/line:./trystuff.p6:60
EVAL callframe(1) file/line:EVAL_9:1
EVAL LEXICAL callframe(1) file/line:EVAL_10:1
EVAL CALLER callframe(1) file/line:EVAL_11:1
------------- [EVAL callframe(2) file/line] ---------------
Local callframe(2) file/line:./trystuff.p6:63
EVAL callframe(2) file/line:gen/moar/m-CORE.setting:789
EVAL LEXICAL callframe(2) file/line:gen/moar/m-CORE.setting:789
EVAL CALLER callframe(2) file/line:gen/moar/m-CORE.setting:789
------------- [EVAL callframe(3) file/line] ---------------
Local callframe(3) file/line:./trystuff.p6:1
EVAL callframe(3) file/line:./trystuff.p6:52
EVAL LEXICAL callframe(3) file/line:./trystuff.p6:53
EVAL CALLER callframe(3) file/line:./trystuff.p6:54
#!/usr/bin/env perl6
sub show_vars($scope) {
my @vars = $scope.keys;
say "vars: {@vars}";
}
sub foo {
my $x = 5;
# say "Lexical keys: {LEXICAL::.keys}";
# say "Lexical keys: {LEXICAL::.keys.perl}";
# say "Lexical keys: {~LEXICAL::.keys}";
say "\n\n------------- [List variables] ---------------";
my @my_vars = LEXICAL::.keys;
my @parent_vars = CALLER::.keys;
say "my vars: {@my_vars}";
say "caller vars: {@parent_vars}";
say "\n\n------------- [Eval Variable] ---------------";
say 'Local $x=' ~ $x;
say 'EVAL $x=' ~ EVAL('$x');
say 'EVAL LEXICAL:: $x=' ~ EVAL('$x', context => LEXICAL::);
say 'EVAL CALLER:: $x=' ~ EVAL('$x', context => CALLER::);
say "\n\n------------- [EVAL var file/line] ---------------";
say 'Local $?FILE/$?LINE:' ~ $?FILE ~ ":" ~ $?LINE;
say 'EVAL $?FILE/$?LINE:' ~ EVAL('$?FILE ~ ":" ~ $?LINE');
say 'EVAL LEXICAL $?FILE/$?LINE:' ~ EVAL('$?FILE ~ ":" ~ $?LINE', context => LEXICAL::);
say 'EVAL CALLER $?FILE/$?LINE:' ~ EVAL('$?FILE ~ ":" ~ $?LINE', context => CALLER::);
say "\n\n------------- [EVAL callframe file/line] ---------------";
say 'Local callframe file/line:' ~ callframe().file ~ ":" ~ callframe().line;
say 'EVAL callframe file/line:' ~ EVAL('callframe().file ~ ":" ~ callframe().line');
say 'EVAL LEXICAL callframe file/line:' ~ EVAL('callframe().file ~ ":" ~ callframe().line', context => LEXICAL::);
say 'EVAL CALLER callframe file/line:' ~ EVAL('callframe().file ~ ":" ~ callframe().line', context => CALLER::);
say "\n\n------------- [EVAL callframe(1) file/line] ---------------";
say 'Local callframe(1) file/line:' ~ callframe(1).file ~ ":" ~ callframe(1).line;
say 'EVAL callframe(1) file/line:' ~ EVAL('callframe(1).file ~ ":" ~ callframe(1).line');
say 'EVAL LEXICAL callframe(1) file/line:' ~ EVAL('callframe(1).file ~ ":" ~ callframe(1).line', context => LEXICAL::);
say 'EVAL CALLER callframe(1) file/line:' ~ EVAL('callframe(1).file ~ ":" ~ callframe(1).line', context => CALLER::);
say "\n\n------------- [EVAL callframe(2) file/line] ---------------";
say 'Local callframe(2) file/line:' ~ callframe(2).file ~ ":" ~ callframe(2).line;
say 'EVAL callframe(2) file/line:' ~ EVAL('callframe(2).file ~ ":" ~ callframe(2).line');
say 'EVAL LEXICAL callframe(2) file/line:' ~ EVAL('callframe(2).file ~ ":" ~ callframe(2).line', context => LEXICAL::);
say 'EVAL CALLER callframe(2) file/line:' ~ EVAL('callframe(2).file ~ ":" ~ callframe(2).line', context => CALLER::);
say "\n\n------------- [EVAL callframe(3) file/line] ---------------";
say 'Local callframe(3) file/line:' ~ callframe(3).file ~ ":" ~ callframe(3).line;
say 'EVAL callframe(3) file/line:' ~ EVAL('callframe(3).file ~ ":" ~ callframe(3).line');
say 'EVAL LEXICAL callframe(3) file/line:' ~ EVAL('callframe(3).file ~ ":" ~ callframe(3).line', context => LEXICAL::);
say 'EVAL CALLER callframe(3) file/line:' ~ EVAL('callframe(3).file ~ ":" ~ callframe(3).line', context => CALLER::);
}
sub bar {
my $x = 2;
my $y = "hi";
foo;
}
bar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment