Include a file

Raku provides a module system that is based primarily on importation of symbols rather than on inclusion of textual code:

use MyModule;

However, one can evaluate code from a file:

require 'myfile.p6';

One can even do that at compile time:

BEGIN require 'myfile.p6'

None of these are true inclusion, unless the require cheats and modifies the current input string of the parser. To get a true textual inclusion, one could define an unhygienic textual macro like this:

macro include(AST $file) { slurp $file.eval }
include('myfile.p6');

Last updated