// X / words W.s:(0#`;_hash 0#`);W.v:W.c:W.f:() w:{[s;v;c;f]:[(#*W.s)>i:W.s?s;W[`v`c`f;i]:(v;c;f);W[`s`v`c`f]:({(x;_hash x)}W.s[0],s;W.v,v;W.c,c;W.f,,f)];} v:{[s]if[(#*w)>i:W.s?s;W[`v`c`f]:W[`v`c`f]_di'i;W.s[0]:W.s[0]_di i;W.s[1]:_hash*W.s]} u:{[v;f;x;y]f[(-v)_ x;y].|(-v)# x} / verbs {w[`$x;2;0;{x[z;y]}[. x]] w[`$x,".";2;0;. x] w[`$x,":";1;0;. x,":"]}'"~!@#$%^&*_-+=|:<,>.?"; / 0: 1: 2: 3: 4: 5: 6: {w[`$x;2;0;{x[z;y]}[. y]] w[`$x,".";2;0;. y] w[`$x,":";1;0;. y,":"]}'[$`zero`one`two`three`four`five`six;"0123456",'":"]; / _x -> x {w[`$x;1;0;."_",x]}'$`log`exp`abs`sqr`sqrt`floor`dot`mul`inv`sin`cos`tan`asin`acos`atan`sinh`cosh`tanh`ci`ic`bd`db`hash`exit; {w[`$x;2;0;{x[z;y]}[."_",x]];w[`$x,".";2;0;."_",x]}'$`draw`in`lin`bin`binl`dv`di`dvl`sv`vs`sm`ss; w[`ssr;3;0;{_ssr[z;y;x]}] / literals ({w[`$x;0;0;y]}'). L:(("nul";"sym";"SYM";"INT";"FLT";"NAN";"nan";"INF";"INF:";"inf";"inf:") ( ;` ;0#` ;!0 ;0#0. ;0N ;0n ;0I ;-0I ;0i ;-0i )); / adverbs w[`")" ;2;0] {a[x]'[y]} / .. x[f]) -> f'[x;..] w[`")." ;2;0] {(a[x]'). y} / x[f]). -> (f'). x w[`"(:" ;2;0] {a[x]':y} / f':x w[`"(" ;3;0] {y a[x]':z} / x f':y w[`"(." ;2;0] {(a[x]':). y} / [f](. -> (f':). x w[`"/:" ;2;0] {a[x]/y} / f/x, v/x, m/x w[`"/" ;3;0] {a[x]/[y;z]} / .. y x[f]/ -> f/[x;y] w[`"/." ;2;0] {(a[x]/). y} / x[f]/. -> (f/). x w[`"\\:" ;2;0] {a[x]\y} / f\x, v\x, m\x w[`"\\" ;3;0] {a[x]\[y;z]} / .. y x[f]/ -> f\[x;y] w[`"\\." ;2;0] {(a[x]\). y} / x[f]\. -> (f\). x w[`"}" ;3;0] {y a[x]\:z} / y x[f]} -> x f/:y w[`"}." ;2;0] {(a[x]\:). y} / [x y][f]}. -> (f/:).(x;y) w[`"{" ;3;0] {y a[x]/:z} / y x[f]{ -> x f\:y w[`"{." ;2;0] {(a[x]/:). y} / [x y][f]{. -> (f\:).(x;y) w[`"{:" ;3;0] {a[y]a[x]/z} / do, while: y x/z w[`"}:" ;3;0] {a[y]a[x]\z} / do, while: y x\z w[`"`" ;-1;0] {a[x]} / [f]` -> f w[`"`." ;-2;0] {a[x][;y]} / x[f]`. -> f[;x] / @ w[`"set1" ;3;0] {[f;x;y]@[y;x;a f]} / @[x;y;f] w[`"set2" ;4;0] {[f;x;y;z]@[z;y;a f;x]} / @[x;y;f;z] w[`"get" ;2;0] {[f;x]@[a f;x]} / @[f;x] w[`"trap" ;2;0] {[f;x]@[a f;x;:]} / @[f;x;:] / . w[`"set1." ;3;0] {[f;x;y].[y;x;a f]} / .[x;y;f] w[`"set2." ;4;0] {[f;x;y;z].[z;y;a f;x]} / .[x;y;f;z] w[`"get." ;2;0] {[f;x].[a f;x]} / .[f;x] w[`"trap." ;2;0] {[f;x].[a f;x;:]} / .[f;x;:] / combinators w[`i ;1;1] u[1;{[x;y;a](x;a,y)}] / [..] -> .. w[`dip ;2;1] u[2;{[x;y;a;b](x;b,(,a),y)}] / x [..] -> .. x w[`sub ;2;1] u[2;{[x;y;a;b](x;o[b;a],y)}] / pattern match / define/undefine w[`";" ;0;1] {:[~#t:(k:y?`";")#y;:(();y);1=#t;v@*t;w[*t;0;0;1_ t]];(x;(k+1)_ y)} / load script w[`load ;1;1] u[1;{[x;y;a]A[()]P@6::["."_in a$:;a;a,".x"];(x;y)}] / miscellaneous X verbs w[`words ;0;0] {**W} w[`signal ;1;0] {'x} w[`trace ;1;0] {:Y::x} w[`parse ;1;0] {P x} w[`represent ;1;0] {R x} / pattern match o:{[t;c]{(."{[x_;y_",x,"]p[x_;y_;",:[1=#t;",",1_ x;1!")(",1_ x],"]}")[t;c]}@,/";",'(#t)#X} / pattern -> function p:{q[y;*{r[y]. x}/[(;|z);x]]} / evaluate pattern q:{:[~@x;@[x;_n;_f;y];x _in!y;y x;x]} / dict -> list r:{:[~@x;(*{r[y]. x}/[(y;*z);x];1_ z);{(x>64)&x<91}_ic*$x;(@[y;x;:;z];());(@[y;x;:;*z];1_ z)]} / list -> dict / quotation -> function a:{:[:[~#x;0;4=t:4:x;1;@x;0;-4=t;1;t<0;0;4_in 4::'x];c .+,/b'x;x]} / quotation -> function b:{:[(#*W.s)=i:W.s?x;,(0;x);W[`v;i];,W[`v`f;i];,/_f'W[`f;i]]} / ((valence;value)..) c:{[n;o]:[n~0;o;*e . 3#d/[(();();();X);o;n]]} / construct d:{[r;o;n]:[~n;f;g][*r;r 1;r 2;r 3;o;n]} / noun, verb, adverb e:{[s;t;u]{{x[y]}/[."{",i[,//y;,//z],j[,//y],"}";k[x,();z,()]]}'[s;t;u]} / head, body, projection f:{[s;t;u;v;o;n](s,,o;t,,*v;u,,1;1_ v)} / noun g:{[s;t;u;v;o;n]k:0|l:n-#s;h'[(0,0|-l)_/:(s;t;u);k#'(;v;0);(o;v k;1)],,(k+1)_ v} / verb/adverb h:{x[0],,y,x[1],z} / .. stack .. expr i:{[t;u]"[",(1_,/";",'t@>u),"]"} / head j:{[t]"**A[()]",:[1=#t;t;1!")(",1_,/";",'t]} / body k:{[s;u](((~4:*:),/'/(u;s))1)@&,//u} / project / parse P:{ P:{ b:" \t\r\n";q:"\"";e:"\\";l:"[";r:"]";c:"'";d:".";t:":";m:"-" / punctuation o:"~!@#$%^&*-_=+|<,>?;`()/\\{}" / operators n:"0123456789" / numbers Q:{(1(0 0 0;1 2 3;1 1 1;0 0 0)\(x="\\")+2*x="\"")?3} / find string N:{(t=x i)+i:&/x?/:b,q,e,l,r,c,t,o,X} / find number :[~#z ;(x;y;z) / done ";;"~2#z ;(x;y;(z?*-1#b)_ z) / comment (*z)_in b ;(x;y;1_ z) / blank (*z)_in d,t ;(.[x;y;,;`$i#z];y;(i:2&(z _lin d,t)?0)_ z) / . : l=*z ;(.[x;y;,;,()];y,#x . y;1_ z) / begin list r=*z ;(.[x;-1_ y;,;()];-1_ y;1_ z) / end list c=*z ;:[e=*1_ z;(.[x;y;,;.q,z[1 2],q];y;3_ z);(.[x;y;,;z 1];y;2_ z)] / character q=*z ;(.[x;y;,;,"",. i#z];y;(i:1+Q 1_ z)_ z) / string (*z)_in n ;(.[x;y;,;.{_ssr[(-t=*-1#x)!x;t;m]}i#z];y;(i:N z)_ z) / number (*z)_in o ;(.[x;y;,;`$i#z];y;(i:1+&/(1_ z)?/:b,q,e,l,r,c,o,X,n)_ z) / operator (*z)_in X ;(.[x;y;,;`$i#z];y;(i:(z _lin X,n,d,t)?0)_ z) / name '"syntax"]} / oops *(P .)/(();!0;x," ")} / represent R:{ R:{:[(#*L)>i:L[1]?y ;L[0;i] / literal (t:4:y)_in 1 2 ;:[y<0;(1_5:y),":";5:y] / number x&t=-3 ;(","=*t)_ t:5:y / deep string t=7 ;"\004" / function t<1 ;{:[x;1!"][",y;y]}[x]1_,/" ",'_f[1]'y / list t=5 ;(1!"][",,/_f[1]'. y)," .:" / dictionary ((~x)&t=-3)|t=3 ;"'",1_-1_5:y / shallow string $y]} / symbol :[#x,:"";R[0;x];x]} / apply A:{U::_T;r:({if[Y>0;T[x;y]];B[*y,();x,()](1_ y),()}.)/(x;y);if[Y<0;`0:,$86400*_T-U];r} B:{:[(~#z)&6=t:4:x;C;4=t;D;7=t;E;F][x;y;z]} C:{(y;z)} D:{:[(#*W.s)=i:W.s?x;F[x];W.c i;W.f i;G[W.f i]][y;z]} E:{:[~#y;F[x;y;z];7=4:r:x[*-1#y];G[r;-1_ y;z];F[r;-1_ y;z]]} F:{(y,,x;z)} G:{(y;x,z)} / trace T:{if[(#x)|#y;`0:(Y$R x)," : ",(-Y)$R y;:[#y;if[#0:`;Y::0];`0:,""]]} / run `0:,"X 2004-12-18 Copyright (C) 2004 Stevan Apter\n" X:_ci,/97 65+\:!26 / a-zA-Z O:();Y:0 / stack, trace {A[()](x;`load)}'(,"x.x"),_i; / load scripts .m.p:" " / prompt .m.r:{ / respond if[x~," ";.m[`r`p]:_n;:_n] / exit to k if[(#x)&&/x=" ";_exit 0] / exit {if[(~.m.p~_n)&~Y;`0:,R x]}O::*A[O]P x} / X read-eval-print \ in K (,/:\:)/(1 2 3;4 5;6 7 8 9) forms the cartesian product of the sublists in X: [[1 2 3][4 5][6 7 8 9]][[[,]}]{[,]/:]/: or: [[1 2 3][4 5][6 7 8 9]][[[join]right]left[join]over:]over: