Last active
December 16, 2015 17:59
-
-
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
This file contains 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
operators IfThenElse | |
group ifthenelse = "If…Then…Else…" | |
ifthenelse -> arithmetic, relations, brackets |
This file contains 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
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