view 2-Io/day2-operators.io @ 60:643eec1f9e3a

Add a custom implementation of append/3
author IBBoard <dev@ibboard.co.uk>
date Wed, 27 Sep 2017 20:48:28 +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