aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-12 22:48:49 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-12 22:48:49 -0400
commitf74d9223ef880f2914030c2375f680dcc7e8c92b (patch)
treedfd7ea8862c2d2cd3a4a3945a7380f5cab361866
parent58cd3c0c4b56cf9e65b7a532e7ecaa3b928a7091 (diff)
Use .sh to check if a variable is an array instead of another member
-rw-r--r--bqn.js16
1 files changed, 8 insertions, 8 deletions
diff --git a/bqn.js b/bqn.js
index 8f70176b..7619e1df 100644
--- a/bqn.js
+++ b/bqn.js
@@ -8,11 +8,11 @@ let call = (f,x,w) => {
return f(x, w);
}
let get1= i => (v=>(assert(v!==null),v))(i[0][i[1]]);
-let get = i => i.a ? arr(i.map(get),i.sh) : get1(i);
+let get = i => i.sh ? arr(i.map(get),i.sh) : get1(i);
let set = (d,id,v) => {
let eq = (a,b) => a.length===b.length && a.every((e,i)=>e===b[i]);
- if (id.a) {
- assert(v.a&&eq(id.sh,v.sh)); id.map((n,j)=>set(d,n,v[j]));
+ if (id.sh) {
+ assert(v.sh&&eq(id.sh,v.sh)); id.map((n,j)=>set(d,n,v[j]));
} else {
let [a,i]=id; assert((a[i]===null)==d); a[i]=v;
}
@@ -70,7 +70,7 @@ let run = (B,O,S) => { // Bytecode, Objects, Sections/blocks
}
// Runtime
-let arr = (r,sh) => {r.sh=sh;r.a=1;return r;}
+let arr = (r,sh) => {r.sh=sh;return r;}
let list = l => arr(l,[l.length]);
let str = s => list(Array.from(s));
let m1 = m => {m.m1=1;return m;}
@@ -83,7 +83,7 @@ let table = m1(f => (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 = m1(f => (x,w) => {
- let s=x.sh;assert(!has(w)&&x.a&&s.length>0);
+ let s=x.sh;assert(!has(w)&&s&&s.length>0);
let l=x.length,r=Array(l);
if (l>0) {
let c=1;for(let i=1;i<s.length;i++)c*=s[i];
@@ -111,7 +111,7 @@ let runtime = run(
,[0,1,2,32,3,8,Infinity,-Infinity,-1]
,[[0,1,0,0],[0,0,3,149],[2,0,2773,6],[0,0,2801,3],[0,0,2805,3],[0,0,2809,3],[1,0,2813,5],[2,0,2831,6],[2,0,2846,6],[2,0,2865,6],[2,0,2887,6],[2,0,2909,6],[0,0,2942,3],[0,0,2954,3],[0,0,2963,3],[1,0,2972,9],[0,0,3092,3],[0,0,3137,4],[1,1,3220,4],[1,1,3296,3],[0,0,3365,3],[0,0,3376,5],[2,0,3465,12],[0,0,3685,4],[0,0,3735,6],[0,0,3834,4],[0,0,4002,4],[0,0,4068,4],[2,0,4179,15],[1,1,4380,2],[0,0,4406,3],[0,0,4435,3],[0,0,4463,3],[0,0,4509,4],[0,0,4615,3],[0,0,4644,3],[0,0,4667,3],[0,0,4690,3],[0,0,4702,3],[0,0,4733,3],[0,0,4739,5],[0,0,4857,5],[0,0,4891,3],[0,0,4900,3],[1,1,4906,2],[2,0,4977,10],[2,0,5036,8],[1,1,5226,2],[1,0,5236,5],[2,1,5277,4],[0,0,5313,8],[0,0,5551,4],[0,0,5634,3],[0,0,5685,4],[0,0,5808,3],[0,0,5859,4],[0,0,6022,3],[0,0,6041,3],[0,0,6074,3],[0,0,6088,7],[0,0,6137,11],[1,0,6406,8],[0,0,6526,4],[0,0,6613,5],[0,0,6770,4],[0,0,6983,3],[0,0,7002,4],[1,0,7074,9],[1,1,7144,3],[1,0,7168,14],[1,1,7606,4],[0,0,7657,4],[0,0,7800,4],[0,0,7867,4],[0,0,8137,3],[2,0,8180,6],[0,0,8209,3],[0,0,8248,3],[0,0,8337,3],[1,1,8393,2],[2,0,8402,13],[1,1,8556,2],[1,1,8571,2],[1,1,8575,2],[0,0,8579,3],[0,0,8591,3],[0,0,8616,3],[1,0,8638,6],[1,0,8770,11],[1,0,9014,5],[0,0,9029,3],[0,0,9044,3],[0,0,9059,3],[1,0,9107,8],[0,0,9256,8],[0,0,9441,5],[0,0,9524,3],[0,0,9543,4],[0,0,9595,3],[1,0,9606,5],[0,0,9617,3],[0,0,9667,3],[0,0,9687,3],[1,0,9742,6],[0,0,9897,6],[0,0,10033,3],[0,0,10062,5],[0,0,10160,10],[0,0,10347,3],[0,0,10449,3],[0,0,10492,3],[0,0,10547,4],[0,0,10609,3],[0,0,10641,3],[0,0,10671,3],[0,0,10794,6],[0,0,10901,6],[0,0,10951,4],[0,0,10981,3],[0,0,11000,4],[1,1,11158,2],[0,0,11162,3],[1,0,11204,5],[1,0,11242,5],[1,0,11253,5],[0,0,11264,14],[0,0,11450,3],[0,0,11472,3],[0,0,11498,3],[0,0,11554,4],[1,0,11616,5],[0,0,11687,3],[0,0,11717,3],[0,0,11736,5],[0,0,11851,3],[0,0,11906,3],[0,0,11930,5],[0,0,12059,3],[0,0,12102,3],[0,0,12189,3],[0,0,12227,3],[0,0,12259,3],[0,0,12277,3],[0,0,12295,3],[0,0,12325,3],[0,0,12368,6],[0,0,12448,3]]
)(list([
- (x,w) => +(x.a===1) // IsArray
+ (x,w) => x.sh?1:0 // IsArray
,(x,w) => 0 // Type
,(x,w) => has(w)?Math.log(x)/Math.log(w):Math.log(x) // Log
,group_len // GroupLen
@@ -123,10 +123,10 @@ let runtime = run(
,(x,w) => (has(w)?w:1)/x // ÷
,(x,w) => has(w)?Math.pow(w,x):Math.exp(x) // ⋆
,(x,w) => Math.floor(x) // ⌊
- ,(x,w) => has(w)?+(x===w):x.a?x.sh.length:0 // =
+ ,(x,w) => has(w)?+(x===w):x.sh?x.sh.length:0 // =
,lesseq // ≤
,(x,w) => list(x.sh) // ≢
- ,(x,w) => (r=>arr(r,has(w)?w:[r.length],1))(x.slice()) // ⥊
+ ,(x,w) => arr(x.slice(),has(w)?w:[x.length]) // ⥊
,(x,w) => x[w] // ⊑
,(x,w) => list(Array(x).fill(undefined).map((_,i)=>i)) // ↕
,table // ⌜