Skip to content

Instantly share code, notes, and snippets.

@joelnet
Last active August 5, 2019 08:42
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelnet/5f70e9d381c5d52bc006d04c6813780a to your computer and use it in GitHub Desktop.
Save joelnet/5f70e9d381c5d52bc006d04c6813780a to your computer and use it in GitHub Desktop.
Boolean Logic with the SKI Combinators
// S and K are primitive function combinators.
const S = a => b => c => a (c) (b (c))
const K = a => b => a
// Non-primitive combinators can be created with S and K.
const C = S (S (K (S (K (S)) (K))) (S)) (K (K))
const I = S (K) (K)
const KI = K (I)
const M = S (I) (I)
const R = S (K (S (K (S)) (K))) (S (K (S (I))) (K))
// Friendly Names given to combinators for readability.
const True = K
const False = KI
const Or = M // a => b => a (a) (b)
const And = R (KI) // a => b => a (b) (a)
const Not = C
// /**
// * πŸ”₯πŸ”₯πŸ”₯ Boolean Logic πŸ”₯πŸ”₯πŸ”₯
// */
And (True) (True) ('πŸ‰') ('πŸ’') //?
And (True) (False) ('πŸ‰') ('πŸ’') //?
And (False) (True) ('πŸ‰') ('πŸ’') //?
And (False) (False) ('πŸ‰') ('πŸ’') //?
Or (True) (True) ('πŸ‰') ('πŸ’') //?
Or (True) (False) ('πŸ‰') ('πŸ’') //?
Or (False) (True) ('πŸ‰') ('πŸ’') //?
Or (False) (False) ('πŸ‰') ('πŸ’') //?
Not (True) ('πŸ‰') ('πŸ’') //?
Not (False) ('πŸ‰') ('πŸ’') //?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment