Created
July 8, 2022 23:41
-
-
Save RodrigoDornelles/cecd64b3b2493ab554e79e3168ca76d4 to your computer and use it in GitHub Desktop.
from scratch boolean logic recreation based on the pure functional paradigm and lambda calculus.
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
const TRUE = (p) => (q) => (p) | |
const FALSE = (p) => (q) => (q) | |
const OR = (p) => (q) => p(p)(q) | |
const NOT = (p) => (p)(FALSE)(TRUE) | |
const AND = (p) => (q) => (p)(q)(FALSE) | |
const PROG = (func) => FALSE(func())(PROG) | |
const PRINT = (text) => () => TRUE(console.log(text)) | |
const IF = (cond) => (execute) => (nonexecute) => (cond(execute)(nonexecute))() | |
PROG | |
( | |
IF(TRUE) | |
( | |
PRINT("IF 1!") ///< execute | |
) | |
) | |
( | |
IF(AND(TRUE)(TRUE)) | |
( | |
PRINT("IF 2!") ///< execute | |
) | |
( | |
PRINT("ELSE 2!") ///< not execute | |
) | |
) | |
( | |
IF(AND(TRUE)(FALSE)) | |
( | |
PRINT("IF 3!") ///< not execute | |
) | |
( | |
PRINT("ELSE 3!") ///< execute | |
) | |
) | |
( | |
IF(OR(TRUE)(FALSE)) | |
( | |
PRINT("IF 4!") ///< execute | |
) | |
( | |
PRINT("ELSE 4!") ///< not execute | |
) | |
) | |
( | |
PRINT('FINAL') ///< execute | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RESULT