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 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'docs') 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) // ⥊ -- cgit v1.2.3