Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 that?

like image 521
Jakob Avatar asked Oct 14 '22 20:10

Jakob


1 Answers

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.

like image 141
jer Avatar answered Dec 17 '22 20:12

jer