// tcK - 3 stacks / K k:,/+{.:'(x,":";x)}'j:"~!@#\$%^&*_-+=|:<,>.?" v:-&0 20 20 / quotation q:{:[7=4:x;`\$\$x;x]} / quote u:{:[4=4:x;.\$x;x]} / unquote / stack operators pop:{(-1_ x;y;z)} popd:{((-2_ x),-1#x;y;z)} dup:{(x,-1#x;y;z)} dup2:{(x,-2#x;y;z)} dupd:{((-2_ x),(2#1#-2#x),-1#x;y;z)} swap:{((-2_ x),|-2#x;y;z)} pair:{((-2_ x),,-2#x;y;z)} / combinators - dip dip:{(-2_ x;({x,,q y}.|-2#x),y;z)} / execute = unlist: unconditional and conditional i:{(-1_ x;(*-1#x),y;z)} ci:{(-2_ x;({(y,,())(~~x,!0)?1}.-2#x),y;z)} / continuations: z = (y;z) cc:{(x;y;(y;z))} / cache continuation c:{(x;*z;z)} / continue z:{(x,,z;y;())} / pop cached continuation xyz:{(*|x),,z} / go to / continuations: z = (x;y;z) cc:{(x;y;(x;y;z))} / cache continuation c:{((-1_*z),-1#x;z 1;z)} / continue z:{(x,,z;y;())} / pop cached continuation xyz:{z;*|x} / go to / call/cc ccc:{(x,cont[(x;y;z)];(*-1#x),y;z)} / call/cc cont:{[k;x;y;z]c[x;y;k]} / apply continuation / debug stop:{\(x;y;z);`0;(x;y;z)} / print p:{`0:,\$*-1#x;(x;y;z)} / print x pp:{`0:,\$*-1#x;(-1_ x;y;z)} / print and pop x p.:{`0:".";(x;y;z)} / print . / eval, apply e:{*(a .)/(();x;())} a:{:[~#y;(x;y;z);g@*y;f[x;y;z];(x,u@*y;1_ y;z)]} g:{:[7=t:4:x;1;~4=t;0;~(*\$x)_in"{(",j]} f:{:[(#k)>i:k?*y;((v[i]_ x),,y[0]. v[i]#x;1_ y;z);y[0][x;1_ y;z]]} / timeslice s:*:'(a .')/{(();x;())}' / define program P: P:d[(..)] d:{[p;x;y;z](x;p,y;z)} / define pseudo-lambda P: P:l[("xyz";(..))] l:{[v;x;y;z](x;(l_[x]. v),y;z)} l_:{:[@z;z;_f[x;y]'@[z;i;:;((-#y)#x)y?/:z i:&z _lin y]]} / examples Loop:d[(cc;1;+;p;c;"never executes")] / e(0;Loop) = loop forever, print incremented x Do:d[(cc;1;-;dup;p;,c;ci;"done";pp)] / e(10;Do) = loop 10 times, print decremented x While:d[(cc;1;swap;_;dup;#:;p;0;>;,c;ci;"done";pp)] / e(10 20 30;While) = loop until empty, print count Rec100:d[(dup;100;<;,(p.;1;+;`Rec100);ci)] / e(0;Rec100) = recurse 100 times, print . Rec:d[((p;1;+;`Rec);i)] / e(0;Rec) = recurse forever, print incremented x F0:d[(cc;,`F1;ci;"done";pp)] / e(1;F0) = F0 -> F1 -> F2 ^ F0 F1:d[("F1";p;`F2;"never executes";p)] F2:d[("F2";p;0;c;"never executes";p)] Pr:d[(cc;dup;#:;0;>;,(dup;*:;pp;1;swap;_;c);ci)] / e(10 20 30;Pr) / co-routines Left:d[(dup;1;+;-:;p;swap;`Right)] / e(0;`Left) or e(0;`Right) Right:d[(dup;1;+;p;`Left)] / stackless Ackermann, e.g. e(2;3;`Ack) Ack:d[(dup2;pair;~: ((popd;1;+) (pop;1;-;1;`Ack) (dupd;1;-;`Ack;(1;-);dip;`Ack)) ci)] \ ack:{:[~x;y+1;~y;_f[x-1;1];_f[x-1;_f[x;y-1]]]}