5

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?

Jakob
  • 24,154
  • 8
  • 46
  • 57

1 Answers1

4

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.

jer
  • 20,094
  • 5
  • 45
  • 69
  • Thanks, that explains the problem. How are we supposed to handle that? One thing I can think of is to create a main-file that first defines all operators that I want to use and then loads the rest of the files in my project. – Jakob Dec 05 '10 at 10:24
  • Exactly. – jer Dec 05 '10 at 13:50