This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Frekvens1's profile picture

Alternative If statements

Started by Frekvens1, 16 October 2018 - 05:00 PM
Frekvens1 #1
Posted 16 October 2018 - 07:00 PM
Alternative If statements

I don't like to use other peoples work, so I make my own "if" statements.
osmarks #2
Posted 13 January 2019 - 11:58 AM
But this uses the or, not and and operators! You need a new version which is free of stuff other people made.
SquidDev #3
Posted 13 January 2019 - 01:17 PM
But this uses the or, not and and operators! You need a new version which is free of stuff other people made.


local _true  = function(x, _) return x end
local _false = function(_, y) return y end

local function _if(cond, t, f) return cond(t, f) end
local function _not(x) return x(_false, _true) end
local function _and(x, y) return x(y, _false) end
local function _or(x, y) return x(_true, y) end


local hungry = _true
local potato = _true

print(_if(hungry, "Grab potato", "Should I eat"))
_if(_and(hungry, potato),
  function() print("That's true!") end,
  function() print("That's false!") end
)()
There we go, reimplemented using Church Booleans. Truly the future is upon us.