Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 2-Io/day2-operators.io @ 46:eac30c1b92da
Add more notes and try to understand the operators
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 20 Sep 2017 20:48:37 +0100 |
parents | 86668d32e162 |
children |
line wrap: on
line source
# Operators are syntactic sugar and can be listed from a table: OperatorTable println # Creating an operator involves defining it with a precedence # (index based on the output from the previous table) OperatorTable addOperator("xor", 11) # And then implementing it on appropriate prototypes # Note that Io is open-edit, like Ruby, so we can screw with core stuff # like Booleans and extend them true xor := method(bool, if(bool, false, true)) false xor := method(bool, if(bool, true, false)) # For some reason I have to work out, the prints don't work here # They print the second value. But running in REPL works and return correct # value (before printing wrong one) (true xor true) println (true xor false) println (false xor true) println (false xor false) println