Io 运算符,似乎无法在文件中创建它们

发布于 2024-10-05 07:21:18 字数 418 浏览 6 评论 0原文

我一直在尝试使用 Io 语言的运算符。在 cli 中一切工作正常,但是一旦我将代码放入文件中,我就会遇到问题。

这是一个小示例(创建一个与 + 执行相同操作的运算符 +++)

OperatorTable addOperator("+++", 3)      # Say that +++ should be an operator
Number +++ := method(v, call target + v) # Define the slot +++ on numbers
(30 +++ 40) println                      # Try it out!

如前所述,这在 cli 中运行良好,但当我尝试在文件中运行它时不起作用。我认为这与在定义运算符之前已准备好文件这一事实有关,但我将如何解决这个问题?

I've being experimenting with operators in the Io language. Everything works fine in the cli, but as soon as I put my code in files instead, I run into problems.

Here's a tiny example (creating an operator +++ that does the same thing as +)

OperatorTable addOperator("+++", 3)      # Say that +++ should be an operator
Number +++ := method(v, call target + v) # Define the slot +++ on numbers
(30 +++ 40) println                      # Try it out!

As mentioned, this works fine in the cli, but doesn't work when I try to run it in a file. I presume it has something to do with the fact that file has been preparsed, before the operator is defined, but how would I work around that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天煞孤星 2024-10-12 07:21:18

这是 Io 中算子洗牌器的限制。发生的情况大致如下:

  1. 源文件被加载,标记化(在此阶段,没有已知的运算符)
  2. 操作符洗牌器运行
  3. 代码被评估

不幸的是,您在操作符洗牌器已经运行后对其进行操作。

This is a limitation of the operator shuffler in Io. What happens is roughly this:

  1. Source file is loaded, tokenized (at this stage, no operators are known)
  2. Operator shuffler runs
  3. Code is evaluated

Unfortunately for you, you're manipulating the operator shuffler after it's already run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文