From f6899943601e9b9787c33f6eccfc5eb3ecb91be9 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 2 Feb 2021 20:41:21 -0500 Subject: Correct implementation for equals on compound functions --- docs/bqn.js | 8 +++++++- test/cases/prim.bqn | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/bqn.js b/docs/bqn.js index c3c2d1ba..ea0ae6d2 100755 --- a/docs/bqn.js +++ b/docs/bqn.js @@ -144,6 +144,12 @@ let lesseq = (x,w) => { if (s==="function"||t==="function") throw Error("𝕨≤𝕩: Cannot compare operations"); return +(s!==t ? s<=t : w<=x); } +let equals = (x,w) => { + let a,b; + if (typeof(w)!=="function" || !(a=w.repr)) return x===w; + if (typeof(x)!=="function" || !(b=x.repr)) return false; + b=b(); return a().every((e,i)=>e===b[i]); +} let table = f => setrepr(()=>[4,f,table], (x,w) => !has(w) ? arr(x.map(e=>call(f,e)),x.sh) : arr([].concat.apply([],w.map(d=>x.map(e=>call(f,e,d)))),w.sh.concat(x.sh))); @@ -222,7 +228,7 @@ let provide = [ ,divide // ÷ ,power // ⋆ ,floor // ⌊ - ,(x,w) => has(w)?+(x===w):x.sh?x.sh.length:0 // = + ,(x,w) => has(w)?+equals(x,w):x.sh?x.sh.length:0 // = ,lesseq // ≤ ,(x,w) => list(x.sh,0) // ≢ ,(x,w) => arr(x.slice(),has(w)?w:[x.length],x.fill) // ⥊ diff --git a/test/cases/prim.bqn b/test/cases/prim.bqn index 04f01882..2152e859 100644 --- a/test/cases/prim.bqn +++ b/test/cases/prim.bqn @@ -42,6 +42,7 @@ 1≡'a'='a' 0≡'a'='A' 1≡{F←+⋄f=f} +1≡{a‿b←⟨+´,+´⟩⋄a=b} 0≡{_op←{𝕗}⋄op='o'} 0≡{F←{𝕩}⋄G←{𝕩}⋄f=g} 1≡{F←{𝕩}⋄f=f} -- cgit v1.2.3