Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Camilotk/7a7efa9bb709ac57f94fe3792b187992 to your computer and use it in GitHub Desktop.
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.
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