Skip to content

Instantly share code, notes, and snippets.

@RodrigoDornelles
Created July 8, 2022 23:41
Show Gist options
  • Save RodrigoDornelles/cecd64b3b2493ab554e79e3168ca76d4 to your computer and use it in GitHub Desktop.
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.
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
)
@RodrigoDornelles
Copy link
Author

RESULT

IF 1!
IF 2!
ELSE 3!
IF 4!
FINAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment