diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-02 20:41:21 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-02 21:09:06 -0500 |
| commit | f6899943601e9b9787c33f6eccfc5eb3ecb91be9 (patch) | |
| tree | 782af545284be8345d338e24ed25e659e62a9036 | |
| parent | 168a106af8b2771d20a2662c1d13c16fa976a68d (diff) | |
Correct implementation for equals on compound functions
| -rwxr-xr-x | docs/bqn.js | 8 | ||||
| -rw-r--r-- | test/cases/prim.bqn | 1 |
2 files changed, 8 insertions, 1 deletions
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} |
