Home > Raku > Suspicious introspection

Suspicious introspection

One of my routines is acting suspicious. I’m almost certain it wilfully misinterprets arguments just so it can throw an exception. There is a way to spy on it.

sub suspicious($a, :$b, *@rest, *%opts) {
    die('imaoutahere!');

    CATCH {
        put (my $sig = &?ROUTINE.signature.gist) ~ ' -> ' ~ $sig.trans(<*@ *%> => <@ %>).EVAL».raku.join(',');
    }
}

suspicious(1, :2b, 3,4,5);
# OUTPUT: ($a, :$b, *@rest, *%opts) -> 1,:b(2),3 4 5,
          imaoutahere!
            in sub suspicious at tmp/2021-03-08.raku line 1910
            in block <unit> at tmp/2021-03-08.raku line 1917

Please note, that the CATCH-block doesn’t do anything to the exception. It is just there to trigger the debugging code. The proper place to put that would be a macro. Alas, macro can’t inject CATCH-blocks that are actually used as exception handlers. It will have to wait for RakuAST, what would also allow me to replace the EVAL-shenanigans with proper code. Another entry in macro-ideas.txt until then.

Categories: Raku
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment