/ flat two-element basis - brent kerby and william tanksley, jr (= 01 with 1 and 0 swapped) / basis (k, o, q) B:2 0 2{[n;f]{:[~n>#x;f[(-n)_ x].(-n)#x]}}'({I_[x;z,()]};{x,(();,2;,0)};{x,(,y;z,y)}); / apply (X y^Y -> X^y[X] Y) A:{:[S<(S_::_T)-S_;(;);(@x)|~#y;(x;y);@*y;T_ .(B[*y]x;1_ y);T_ .(x,1#y;1_ y)]} / inner interpreter (B -> B) I_:{*(A .)/(x;y)};I:I_[()] / milliseconds to terminate S:0i;S_:0. / outer interpreter (V -> V) O_:{S_::_T;{if[#x;`0:,x]}C I_ . T_[I P D x;P D y]};O:O_[""] / trace T:0;T_:{if[T;`0:,(T\$C x),":",(-T)\$C y];(x;y)} / parse (S -> B) P:{:[~-3=4:x;x *({:[~#z;(x;y;z) "["~*z;(.[x;y;,;,()];y,#x . y;1_ z) "]"~*z;(.[x;-1_ y;,;()];-1_ y;1_ z) (.[x;y;{x,,0\$y};*z];y;1_ z)]} .)/(();!0;x)]} / deconstruct (V -> S) D:{{_ssr/[_ssr/[x;{x[0],"[]",(1_-1_ x),"[]",*|x}'*Q;Q 1];!V;V[]]}/[x,""]_dv" "} / construct (B -> V) C:1_-1_{if[@x;:" * "];v:D'V[];v,:D'*Q;v,:\$!3;v@:i:>#:'v;s:\$((!V),(*Q),0 1,`q)i;R[s;v;x]}@ / represent (bB -> V) R:{r:"";while[#z if[~b:@k:*z;r,:_f[x;y]k;z:1_ z] if[b;j:+/&\@:'z;h:,/\$j#z;z:j _ z while[#h;m:((|1+!j)#\:h)~\:/:y;h:(j-(|/m)?1)_ h;r,:" ",x(|/+m)?1]]] r:_ssr/[;(2!" ",|:)'n;n:,/'\$+2 2_vs!4]/r r:_ssr/[;("[[] ";" [[]";"[]] ";" []]");"[[]]"]/r d:{((x=" ")?0)_ x};r:1!"][",|d@|d r r} / vocabulary (V) V.zap:"10" V.q:"1 zap 0" V.i:"[] q 0" V.unit:"[] q zap" V.nip:"unit 0" V.swat:"q nip" V.dip:"[] q zap [0] [] unit [q] [] unit swat swat swat q 0 q 0" V.swap:"unit dip" V.loop:"zap 0 zap 0 zap zap zap [] 0 zap" / quotations Q:+(("[]";" 1 zap zap ");("[q]";" 1 q zap 0 ");("[0]";" 1 [] q q zap 0 0 ")) \ x = C P D x / prompt/respond .m.p:,":";.m.r:{:[x~," ";.m[`p`r]:_n;O x];}