Last active
August 29, 2015 14:14
-
-
Save dealingwith/f135e9883cb697063c8c to your computer and use it in GitHub Desktop.
functional if in Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print_true() | |
print("true") | |
end | |
function print_false() | |
print("false") | |
end | |
function fif(val, a, b) | |
if val then a() else b() end | |
end | |
function fif_flip(val, a, b) | |
if val then a() else b() end | |
return not val | |
end | |
fif(true, print_true, print_false) -- prints "true" | |
var x = fif_flip(false, print_true, print_false) -- prints "false", returns true | |
-- x is true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment