Who likes keywords? Nobody likes keywords, so why use them?
You know what keyword I use too much? if
! We should make a function called _if
, with its arguments as a logical test and two functions/lambdas where the first function is executed if the boolean is true, and the second if it's false, like an if/else statement, so that we don't have to mess around with those nasty keywords! Even so, It should support truthy/falsy types just like the keyword.
_if(true, (() -> console.log 'true'), (() -> console.log 'false'))
// Logs 'true' to the console.
void the_true() { printf("true"); }
void the_false() { printf("false"); }
_if(true, the_true, the_false);
/* Logs "true" to the console */
the_true: mov rdi .true jmp printf .true: db `true\0` the_false: mov rdi, .false jmp printf .false: db `false\0`
mov dil, 1 mov rsi, the_true mov rdx, the_false call _if ; Logs "true" to the console
void TheTrue() { std::cout << "true" }
void TheFalse() { std::cout << "false" }
_if(true, TheTrue, TheFalse);
// Logs 'true' to the console.
Kata.If(true, () => Console.WriteLine("True"), () => Console.WriteLine("False"));
// write "True" to console
_if(true, fn -> IO.puts "true" end, fn -> IO.puts "false" end)
# prints "true" to the console
main = _if True (putStrLn "You spoke the truth") (putStrLn "liar")
-- puts "You spoke the truth" to the console.
_if False "Hello" "Goodbye" -- "Goodbye"
_if(true, function(){console.log("True")}, function(){console.log("false")})
// Logs 'True' to the console.
_if(true, proc{puts "True"}, proc{puts "False"})
# Logs 'True' to the console.
def truthy(): print("True")
def falsey(): print("False")
_if(True, truthy, falsey)
# prints 'True' to the console
_if(true, || println!("true"), || println!("false"))
# prints "true" to the console
kata._if(true, function() print("true") end, function() print("false") end)
-- prints "true" to the console