Forked from RodrigoDornelles/from-scratch-boolean.js
Created
October 6, 2023 12:33
-
-
Save Camilotk/7a7efa9bb709ac57f94fe3792b187992 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