Io 运算符,似乎无法在文件中创建它们
我一直在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 Io 中算子洗牌器的限制。发生的情况大致如下:
不幸的是,您在操作符洗牌器已经运行后对其进行操作。
This is a limitation of the operator shuffler in Io. What happens is roughly this:
Unfortunately for you, you're manipulating the operator shuffler after it's already run.