diff options
author | Kyle Serrecchia | 2025-01-30 19:28:06 -0800 |
---|---|---|
committer | Kyle Serrecchia | 2025-01-30 19:28:06 -0800 |
commit | 043d4cf37e0085dbb31d73b4156f5561fd2b3160 (patch) | |
tree | 99e3c7a5f653c749333cec194fc95276f29d59a2 /j/javascript/lambda-core.js | |
parent | 9f86e33013615d6f1af60056efeaf2aa2479acc0 (diff) |
restructured folders
Diffstat (limited to 'j/javascript/lambda-core.js')
-rw-r--r-- | j/javascript/lambda-core.js | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/j/javascript/lambda-core.js b/j/javascript/lambda-core.js deleted file mode 100644 index 5b4d7c9..0000000 --- a/j/javascript/lambda-core.js +++ /dev/null @@ -1,55 +0,0 @@ -// LOGIC -const _true = x => y => x; -const _false = x => y => y; -const _not = b => b(_false)(_true) -const _and = b1 => b2 => b1(b2)(_false) -const _or = b1 => b2 => b1(_true)(b2) - -// CHURCH NUMERALS -const _zero = f => x => x; -const _succ = n => f => x => f(n(f)(x)) -const _pred = n => f => x => n(g => h => h(g(f)))(u => x)(a => a) -const _one = _succ(_zero) - -// HELPERS - not pure lambda calculus -const readBool = b => console.log(b("t")("f")) -const readChurch = n => console.log(n(x => x+1)(0)) - -// ------------------------------------------------- - -// EXAMPLES -console.log("LOGIC") -console.log("---------------") -console.log("TRUE/FALSE") -readBool(_true) // t -readBool(_false) // f - -console.log("NOT") -readBool(_not(_true)) // f -readBool(_not(_false)) // t - -console.log("AND") -readBool(_and(_true)(_true)) // t -readBool(_and(_true)(_false)) // f -readBool(_and(_false)(_true)) // f -readBool(_and(_false)(_false)) // f - -console.log("OR") -readBool(_or(_true)(_true)) // t -readBool(_or(_true)(_false)) // t -readBool(_or(_false)(_true)) // t -readBool(_or(_false)(_false)) // f - -console.log("\nCHURCH NUMERALS") -console.log("---------------") -console.log("ZERO/SUCC") -readChurch(_zero) // 0 -readChurch(_one) // 1 -readChurch(_succ(_one)) // 2 -readChurch(_succ(_succ(_one))) // 3 - -console.log("PRED") -readChurch(_pred(_one)) // 0 -readChurch(_pred(_succ(_one))) // 1 -readChurch(_pred(_succ(_succ(_one)))) // 2 - |