开发者

Io operators, cant seem to create them in a file

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 t开发者_如何学Pythonhat?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜