Created
November 6, 2013 05:31
-
-
Save animatedlew/7331407 to your computer and use it in GitHub Desktop.
Here I implement 'and' & 'or' functions using standard if-else expressions.
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
// If the second parameter isn't set to eval as CBN | |
// then infinite loops will hang before the method even begins | |
def and(x: Boolean, y: => Boolean) = | |
if (x) y else false | |
and(true, false) | |
and(false, true) | |
and(false, false) | |
and(true, true) | |
def or(x: Boolean, y: => Boolean) = | |
if (x) true else if (y) true else false | |
or(true, true) | |
or(true, false) | |
or(false, true) | |
or(false, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment