view 2-Io/day2-operators.io @ 37:86668d32e162

Add Day 2 code
author IBBoard <dev@ibboard.co.uk>
date Tue, 12 Sep 2017 20:58:51 +0100
parents
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