37
|
1 # Operators are syntactic sugar and can be listed from a table:
|
|
2 OperatorTable println
|
|
3
|
|
4 # Creating an operator involves defining it with a precedence
|
|
5 # (index based on the output from the previous table)
|
|
6 OperatorTable addOperator("xor", 11)
|
|
7
|
|
8 # And then implementing it on appropriate prototypes
|
|
9 # Note that Io is open-edit, like Ruby, so we can screw with core stuff
|
|
10 # like Booleans and extend them
|
|
11 true xor := method(bool, if(bool, false, true))
|
|
12 false xor := method(bool, if(bool, true, false))
|
|
13
|
|
14 # For some reason I have to work out, the prints don't work here
|
|
15 # They print the second value. But running in REPL works and return correct
|
|
16 # value (before printing wrong one)
|
|
17 (true xor true) println
|
|
18 (true xor false) println
|
|
19 (false xor true) println
|
|
20 (false xor false) println
|
|
21
|