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:
- Source file is loaded, tokenized (at this stage, no operators are known)
- Operator shuffler runs
- Code is evaluated
Unfortunately for you, you're manipulating the operator shuffler after it's already run.
精彩评论