This file will be foo.pm6:
sub bar { "quux" }
say "Loaded";
Run Code Online (Sandbox Code Playgroud)
And this one requirer.p6:
require "foo.pm6";
say bar;
Run Code Online (Sandbox Code Playgroud)
require fails silently, not loading foo.pm6, and bar is not found. This also fails:
require foo;
say bar;
Run Code Online (Sandbox Code Playgroud)
with the same error, about not finding bar. This file:
require ::"foo";
say bar;
Run Code Online (Sandbox Code Playgroud)
Fails even strangely, with MVMArray: Can't shift from an empty array
UPDATE: it fails silently because it stops when it finds an unknown symbol, bar, so it's not running "It's loaded" before it produces the error. Still, the last error is weird.
Undeclared routine:
bar used at line 9. Did you mean 'bag', 'VAR'?
Run Code Online (Sandbox Code Playgroud)
So once that is out of the way, is bar actually imported? If it is, in which package name? How can I use it?
您可以使用lib将当前目录添加到库搜索路径。
如果我的补充export性状bar()在foo.pm6:
sub bar is export { "quux" }
say "Loaded";
Run Code Online (Sandbox Code Playgroud)
以下似乎有效(requirer.p6):
use v6;
use lib '.';
require foo <&bar>;
say bar;
Run Code Online (Sandbox Code Playgroud)
输出:
Loaded
quux
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75 次 |
| 最近记录: |