diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-11 14:58:27 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-11 14:58:27 -0500 |
| commit | ae8d0791777e9ff3e43569089ddd446b666ac626 (patch) | |
| tree | 51a9ceac3d9550e9ab40799b4d63ee496409dae6 /docs/bqn.js | |
| parent | f07e748444200bad23c6a44a30af82bc7b7c8e48 (diff) | |
Allow a left argument to Scan (`)
Diffstat (limited to 'docs/bqn.js')
| -rwxr-xr-x | docs/bqn.js | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/docs/bqn.js b/docs/bqn.js index 4705757c..c16eb0bc 100755 --- a/docs/bqn.js +++ b/docs/bqn.js @@ -154,14 +154,20 @@ 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))); let scan = f => setrepr(()=>[4,f,scan], (x,w) => { - if (has(w)) throw Error("`: No dyadic form"); let s=x.sh; if (!s||s.length===0) throw Error("`: 𝕩 must have rank at least 1"); + if (has(w)) { + let r=w.sh, wr=r?r.length:0; + if (1+wr!==s.length) throw Error("`: rank of 𝕨 must be cell rank of 𝕩"); + if (!r) w=[w]; + else if (!r.every((l,a)=>l===s[1+a])) throw Error("`: shape of 𝕨 must be cell shape of 𝕩"); + } let l=x.length,r=Array(l); if (l>0) { let c=1;for(let i=1;i<s.length;i++)c*=s[i]; let i=0; - for(;i<c;i++) r[i]=x[i]; + if (!has(w)) { for(;i<c;i++) r[i]=x[i]; } + else { for(;i<c;i++) r[i]=call(f,x[i],w[i]); } for(;i<l;i++) r[i]=call(f,x[i],r[i-c]); } return arr(r,s,x.fill); |
