diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/life.combinators.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/js/life.combinators.js b/js/life.combinators.js index 452c767..eeae17b 100644 --- a/js/life.combinators.js +++ b/js/life.combinators.js @@ -1,16 +1,16 @@ /* -identity I a → a -constant K a → b → a -apply A (a → b) → a → b -thrush T a → (a → b) → b -duplication W (a → a → b) → a → b -flip C (a → b → c) → b → a → c -compose B (b → c) → (a → b) → a → c -substitution S (a → b → c) → (a → b) → a → c -chain S_³ (a → b → c) → (b → a) → b → c -converge S2³ (b → c → d) → (a → b) → (a → c) → a → d -psi P (b → b → c) → (a → b) → a → a → c -fix-point4 Y (a → a) → a +identity I a → a +constant K a → b → a +apply A (a → b) → a → b +thrush T a → (a → b) → b +duplication W (a → a → b) → a → b +flip C (a → b → c) → b → a → c +compose B (b → c) → (a → b) → a → c +substitution S (a → b → c) → (a → b) → a → c +chain S_³ (a → b → c) → (b → a) → b → c +converge S2³ (b → c → d) → (a → b) → (a → c) → a → d +psi P (b → b → c) → (a → b) → a → a → c +fix-point4 Y (a → a) → a ref: https://www.willtaylor.blog/combinators-and-church-encoding-in-javscript/ @@ -22,7 +22,7 @@ const A = f => x => f (x) const T = x => f => f (x) const W = f => x => f (x) (x) const C = f => y => x => f (x) (y) -const B = f => g => x => f (g (x)) // FIXME: but what happens when, say, g is a value like TRUE and not a function? +const B = f => g => x => f (g (x)) const S = f => g => x => f (x) (g (x)) const S_ = f => g => x => f (g (x)) (x) const S2 = f => g => h => x => f (g (x)) (h (x)) @@ -42,13 +42,14 @@ const Y = f => (g => g (g)) (g => f (x => g (g) (x))) // S2(I)(I)(I)(1) // 1 // P(I)(I)(1)(2) // 1 // Y(I)(1) // 1 + (function() { console.log('validating combinators'); console.assert(I(1) === 1, 'I failed'); console.assert(K(1)(2) === 1, 'K failed'); console.assert(A(I)(1) === 1, 'A failed'); console.assert(T(1)(I) === 1, 'T failed'); - console.assert(W(I)(1) === 1, 'W failed'); + console.assert(W(I)(1) === 1, 'W failed'); // FIXME: Does this really work? console.assert(C(I)(1)(2) === 1, 'C failed'); console.assert(B(I)(I)(1) === 1, 'B failed'); console.assert(S(I)(I)(1) === 1, 'S failed'); @@ -69,6 +70,7 @@ const nextBoardState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I)))))) // validate countLiveNeighbors rules (function() { // FIXME: I think I messed up these test values, maybe? + // FIXME: I also don't think this'll work given that the combinators will only grok 1 arg that is another combinator...right? console.log('validating countLiveNeighbors'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 1, 1) === 4, 'countLiveNeighbors 1 failed'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 0, 0) === 2, 'countLiveNeighbors 2 failed'); |