Skip to content

Instantly share code, notes, and snippets.

@Villane
Last active December 16, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Villane/5474466 to your computer and use it in GitHub Desktop.
Save Villane/5474466 to your computer and use it in GitHub Desktop.
Syntax sugar: if type () -> X (nullary function returning X) is expected and we have an expression of type X, convert the expression into a lambda: () -> expr This allows custom functions to implement control structures like if-then-else, where the branches are evaluated only if needed
operators IfThenElse
group ifthenelse = "If…Then…Else…"
ifthenelse -> arithmetic, relations, brackets
extern puts(s: Byte *): Unit
extending Boolean {
def `If…Then…Else…`(thenB: () -> (), elseB: () -> ()) =
if this then thenB() else elseB()
def &&(that: () -> Boolean) = if this then that() else false
def ||(that: () -> Boolean) = if ¬this then that() else true
}
def main() = {
// lambdaize! lambdaize!
If true Then puts("Then") Else puts("Else");
if false && { puts("Word"); true } then puts("Word") // doesn't print anything
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment