找不到List::Util

huangapple go评论94阅读模式
英文:

Could not find List::Util

问题

这段代码来自 https://stackoverflow.com/questions/75354706/why-is-raku-reporting-two-terms-in-a-row-when-i-define-a-new-operator.

以以下方式开始:

unit module Format;
use List::Util;
...

但编译失败,显示以下错误信息:

 raku ./main.raku
===SORRY!=== Error while compiling /home/runner/l4gp3hvdnhd/./main.raku
Could not find List::Util in:
    inst#/home/runner/.raku
    inst#/opt/rakudo-pkg/share/perl6/site
    inst#/opt/rakudo-pkg/share/perl6/vendor
    inst#/opt/rakudo-pkg/share/perl6/core
    ap#
    nqp#
    perl5#
at /home/runner/l4gp3hvdnhd/./main.raku:3
exit status 1

与此同时,我发现这是一个有效的模块 - https://raku.land/zef:lizmat/List::Util

为什么会失败?

英文:

I'm trying to compile some raku code I saw on https://replit.com/languages/raku. The code is from https://stackoverflow.com/questions/75354706/why-is-raku-reporting-two-terms-in-a-row-when-i-define-a-new-operator.

It begins like this:

unit module Format;
use List::Util;
...

It fails to compile with:

 raku ./main.raku
===SORRY!=== Error while compiling /home/runner/l4gp3hvdnhd/./main.raku
Could not find List::Util in:
    inst#/home/runner/.raku
    inst#/opt/rakudo-pkg/share/perl6/site
    inst#/opt/rakudo-pkg/share/perl6/vendor
    inst#/opt/rakudo-pkg/share/perl6/core
    ap#
    nqp#
    perl5#
at /home/runner/l4gp3hvdnhd/./main.raku:3
exit status 1

On the other hand I see this is a valid module - https://raku.land/zef:lizmat/List::Util.

Why is it failing?

答案1

得分: 4

您没有安装List::Util。由于您正在使用在线解释器,您很可能会遇到很多麻烦。我建议您改为使用rakubrew在本地安装Raku。

然后运行以下命令:

rakubrew download # 将安装最新的Raku和zef
zef install List::Util

现在您应该能够在本地运行您的代码,并且您将能够访问List::Util库。

英文:

You do not have List::Util installed. Since you're using an online interpreter you will most likely have a lot of trouble doing this. Instead I recommend installing Raku on your local machine with rakubrew.

Then run the following commands:

rakubrew download # Will install latest raku and zef
zef install List::Util

Now you should be able to run your code on your local machine, and you'll have access to the List::Util library.

答案2

得分: 4

TL;DR 在控制台中运行 zef install --/test List::Util,将 use lib '.'; 放在你的 Raku main.raku 的顶部,立即运行你的程序,不要犹豫,否则小鬼们会快乐地让你的努力付之东流。或者也许只是听听 Liz 和 Rawley 的建议。


正如 Liz 和 Rawley 所指出的,你需要安装 List::Util

但是,虽然在实践中我大体同意他们的观点(使用 replit 可能会让你的尝试变得麻烦),我认为补充一个不同的响应可能会有所帮助。


replit 正试图通过某些方式与其他在线评估器区分开来,即它试图模拟一个完整的开发环境。

事实上,在他们雄心勃勃的项目早期阶段,乞丐不能选择(如果你不付费,如果事情不像你想的那样进行,那就很难抱怨),但是对于这个 Stack Overflow(SO)来说,值得注意的是它确实具有控制台/Shell 功能,并且他们已经安装了 Rakudo Star,或者类似它的东西,包括几乎所有人都在使用的 Raku 软件包管理器(zef)。

因此,这个命令在 replit 的控制台中的一个新的 raku 会话中运行成功:

zef install --/test List::Util;

--/test 告诉 zef 不要运行测试。我只有一个免费账户,当我仅运行 zef install List::Util 时,似乎 replit 终止了 zef 的进程。可能是因为测试太耗时,但我不确定。)

然后这个 main.raku 也起作用:

use lib '.';              # 告诉 Raku(do) 库在当前目录。
use List::Util <notall>;  # 从模块加载并导入 `notall`。
say notall { 42 }, 99;    # 尝试一下。

但是现在出现了一个问题。当我正在撰写这个答案时,预料之中的事情发生了。我的互联网连接短暂故障,replit 重新启动了会话,尽管我的 main.raku 代码被恢复了,但 List::Util 和我的控制台历史都消失了,所以我不得不再次粘贴安装命令并重新运行以再次安装模块。

这只是一种一次性的容器魔法,迄今为止 replit 所做的模拟真正的完整本地开发环境的工作是有限的。

也许,如果你的互联网连接非常稳定和/或你使用的是付费的 replit 账户和/或正值满月,一切都会顺利进行。或者也许你最好遵循 Rawley 的建议。


说到这一点(我指的是 Rawley 建议设置你的 Raku 开发环境),如果你在本地安装,你也可以安装 CommaIDE 的免费版。

英文:

TL;DR Run zef install --/test List::Util in the console, put use lib &#39;.&#39;; at the top of your Raku main.raku, and run, don't walk, with your program, before gremlins gleefully render your efforts in vain. Or maybe just listen to Liz and Rawley.


As Liz and Rawley have noted, you need List::Util installed.

But while I largely agree with them in practice (it may be a pain to use replit to do what you're trying to do) I think a different response to complement theirs might be helpful.


One of the ways replit is trying to distinguish itself from other online evaluators, is that it is trying to be akin to a full dev environment.

In reality it's early days in their ambitious project, and beggars can't be choosers (if you're not paying, it's hard to complain if things don't work out as you might want), but of particular relevance for this SO it is worth noting that it does have console/shell facilities and they've installed Rakudo Star, or perhaps just something like it, including the Raku package manager pretty much everyone uses (zef).

Thus this command, which I just ran in replit's console of a new raku session, worked:

zef install --/test List::Util;

(The --/test tells zef not to run tests. I've only got a free account and it looked like replit killed zef's process when I ran just zef install List::Util during its running of tests. Presumably they take too long, but I don't know.)

And then this main.raku also worked:

use lib &#39;.&#39;;              # Tell Raku(do) libs are in current directory.
use List::Util &lt;notall&gt;;  # Load and import `notall` from module.
say notall { 42 }, 99;    # Try it.

But now the rub. As I was composing this answer, the expected happened. My internet connection momentarily flaked out, the replit rebooted the session, and while my main.raku code was rescued, both List::Util and my console history had disappeared, so I had to paste the install command again and rerun it to get the module installed again.

It's all just throwaway container magic, and there's only so much replit has done thus far to make the simulation of a real full local dev environment really work.

Maybe if your Internet connection is rock solid and/or you're using a paid replit account and/or it's the full moon, it'll all work out. Or maybe you're best off following Rawley's advice.


Speaking of which (I mean Rawley's advice to set up your Raku dev environment locally), if you do install locally you can also install the awesome free version of CommaIDE.

huangapple
  • 本文由 发表于 2023年2月6日 18:00:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定