improve ⊸⟜

This commit is contained in:
dzaima 2021-08-01 03:53:48 +03:00
parent e5d876eb80
commit 86b3882c5e
2 changed files with 32 additions and 12 deletions

View File

@ -98,10 +98,11 @@ B repeat_c1(B d, B x) { REPEAT_T(c1,{} ); }
B repeat_c2(B d, B w, B x) { REPEAT_T(c2,dec(w), inc(w), ); }
#undef REPEAT_T
B before_c1(B d, B x) { return c2(c(Md2D,d)->g, c1i(c(Md2D,d)->f, inc(x)), x); }
B before_c2(B d, B w, B x) { return c2(c(Md2D,d)->g, c1i(c(Md2D,d)->f, w ), x); }
B after_c1(B d, B x) { return c2(c(Md2D,d)->f, x, c1i(c(Md2D,d)->g, inc(x))); }
B after_c2(B d, B w, B x) { return c2(c(Md2D,d)->f, w, c1i(c(Md2D,d)->g, x )); }
B before_c1(B d, B x) { return c2(c(Md2D,d)->g, c1iX(c(Md2D,d)->f, x), x); }
B before_c2(B d, B w, B x) { return c2(c(Md2D,d)->g, c1i (c(Md2D,d)->f, w), x); }
B after_c1(B d, B x) { return c2(c(Md2D,d)->f, x, c1iX(c(Md2D,d)->g, x)); }
B after_c2(B d, B w, B x) { return c2(c(Md2D,d)->f, w, c1i (c(Md2D,d)->g, x)); }
B atop_c1(B d, B x) { return c1(c(Md2D,d)->f, c1(c(Md2D,d)->g, x)); }
B atop_c2(B d, B w, B x) { return c1(c(Md2D,d)->f, c2(c(Md2D,d)->g, w, x)); }
B over_c1(B d, B x) { return c1(c(Md2D,d)->f, c1(c(Md2D,d)->g, x)); }
@ -109,12 +110,12 @@ B over_c2(B d, B w, B x) { B xr=c1(c(Md2D,d)->g, x); return c2(c(Md2D,d)->f, c1(
B cond_c1(B d, B x) { B g=c(Md2D,d)->g;
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1");
usz fr = WRAP(o2i64(c1(c(Md2D,d)->f, inc(x))), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘"));
usz fr = WRAP(o2i64(c1iX(c(Md2D,d)->f, x)), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘"));
return c1(TI(g,getU)(g, fr), x);
}
B cond_c2(B d, B w, B x) { B g=c(Md2D,d)->g;
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1");
usz fr = WRAP(o2i64(c2(c(Md2D,d)->f, inc(w), inc(x))), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘"));
usz fr = WRAP(o2i64(c2iWX(c(Md2D,d)->f, w, x)), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘"));
return c2(TI(g,getU)(g, fr), w, x);
}

31
src/h.h
View File

@ -452,18 +452,37 @@ static B c2(B f, B w, B x) { // BQN-call f dyadically; consumes w,x
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x));
return c2_rare(f, w, x);
}
static void errMd(B x) { if(RARE(isMd(x))) thrM("Calling a modifier"); }
// like c1/c2, but with less overhead on non-functions
static B c1i(B f, B x) {
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x));
dec(x);
if (isMd(f)) thrM("Calling a modifier");
return inc(VALIDATE(f));
dec(x); errMd(f);
return inc(f);
}
static B c2i(B f, B w, B x) {
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x));
dec(w); dec(x);
if (isMd(f)) thrM("Calling a modifier");
return inc(VALIDATE(f));
dec(w); dec(x); errMd(f);
return inc(f);
}
static B c1iX(B f, B x) { // c1 but implicit inc(x)
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, inc(x)));
errMd(f);
return inc(f);
}
static B c2iX(B f, B w, B x) { // c2 but implicit inc(x)
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, inc(w), x));
dec(w); errMd(f);
return inc(f);
}
static B c2iW(B f, B w, B x) { // c2 but implicit inc(w)
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, inc(x)));
dec(x); errMd(f);
return inc(f);
}
static B c2iWX(B f, B w, B x) { // c2 but implicit inc(w);inc(x)
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, inc(w), inc(x)));
errMd(f);
return inc(f);
}