You can save code to a file and compile it with raku -c. Is there any way to do the same programatically, using some public API?
You can save code to a file and compile it with raku -c. Is there any way to do the same programatically, using some public API?
There is an undocumented named parameter :check to EVAL that will prevent the compiled code from actually running. It will return Nil on success. If there are any errors, it will throw like it otherwise also would.
$ raku -e 'q/say "foo"/.EVAL'
foo
$ raku -e 'q/zay "foo"/.EVAL'
===SORRY!=== Error while compiling ...
Undeclared routine:
zay used at line 1. Did you mean 'say'?
$ raku -e 'say q/say "foo"/.EVAL(:check)'
Nil
Perhaps that named parameter should be documented.
EDIT: Please note that this will not prevent BEGIN blocks from being run, as @ugexe pointed out.