Created
December 10, 2012 22:51
-
-
Save ashmoran/4254066 to your computer and use it in GitHub Desktop.
Adding a new operator in Io - woah!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OperatorTable println | |
"ADDING A NEW OPERATOR!!!" println | |
"" println | |
OperatorTable addOperator("^|", 11) | |
true ^| := method(bool, if(bool, false, true)) | |
false ^| := method(bool, if(bool, true, false)) | |
OperatorTable println | |
"Let's see if it works..." println | |
"========================" println | |
"" println | |
"true ^| true:" println | |
true ^| true println | |
"true ^| false:" println | |
true ^| false println | |
"false ^| true:" println | |
false ^| true println | |
"false ^| false:" println | |
false ^| false println |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ io io new_operator.io | |
OperatorTable_0x7fd8e84760d0: | |
Operators | |
0 ? @ @@ | |
1 ** | |
2 % * / | |
3 + - | |
4 << >> | |
5 < <= > >= | |
6 != == | |
7 & | |
8 ^ | |
9 | | |
10 && and | |
11 or || | |
12 .. | |
13 %= &= *= += -= /= <<= >>= ^= |= | |
14 return | |
Assign Operators | |
::= newSlot | |
:= setSlot | |
= updateSlot | |
To add a new operator: OperatorTable addOperator("+", 4) and implement the + message. | |
To add a new assign operator: OperatorTable addAssignOperator("=", "updateSlot") and implement the updateSlot message. | |
ADDING A NEW OPERATOR!!! | |
OperatorTable_0x7fd8e84760d0: | |
Operators | |
0 ? @ @@ | |
1 ** | |
2 % * / | |
3 + - | |
4 << >> | |
5 < <= > >= | |
6 != == | |
7 & | |
8 ^ | |
9 | | |
10 && and | |
11 ^| or || | |
12 .. | |
13 %= &= *= += -= /= <<= >>= ^= |= | |
14 return | |
Assign Operators | |
::= newSlot | |
:= setSlot | |
= updateSlot | |
To add a new operator: OperatorTable addOperator("+", 4) and implement the + message. | |
To add a new assign operator: OperatorTable addAssignOperator("=", "updateSlot") and implement the updateSlot message. | |
Let's see if it works... | |
======================== | |
true ^| true: | |
true | |
true ^| false: | |
false | |
false ^| true: | |
true | |
false ^| false: | |
false | |
➜ io |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment