Jump to content




Alternative If statements

lua

2 replies to this topic

#1 Frekvens1

  • Members
  • 6 posts

Posted 16 October 2018 - 06:00 PM

Alternative If statements

I don't like to use other peoples work, so I make my own "if" statements.
Posted Image

#2 osmarks

  • Members
  • 22 posts

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.

#3 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 13 January 2019 - 01:17 PM

View Postosmarks, on 13 January 2019 - 11:58 AM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users