如何从解释器执行 raku 脚本?

How to execute raku script from interpreter?

我这样打开raku/rakudo/perl6:

con@V:~/Scripts/perl6$ perl6
To exit type 'exit' or '^D'
> 

上面的环境叫“解释器”吗?我一直在寻找,但找不到它的名字。

如何像我那样执行 rakudo 脚本

source('script.R') 在 R 中,或 exec(open('script.py').read()) 在 python3?

澄清一下,我希望脚本中的函数和库可以在 REPL 中使用,run 似乎没有。

我确定它存在于文档 某处 但我找不到它:(

它被称为读取-评估-打印循环REPL. You can execute raku scripts direct in the shell: raku filename.raku without REPL. To run code from REPL you can have a look at run (run <raku test.raku> ) or EVALFILE

rosettacode 页面 Include a file 有一些信息。但目前看来没有完全替代您的 R source('script.R') 示例的方法。

正如 Valle Lukas 所说,没有确切的替代品。但是,运行 外部程序具有所有常用功能,

  • shell("raku multi-dim-hash.raku") 将 运行 作为外部程序。
  • IIRC,source 也评估了来源。所以你可能想使用 require,尽管符号不会被直接导入,你必须为此使用间接查找。
  • 您也可以在加载的模块上使用 EVAL,但同样不会导入变量和符号。