// XY 0.0 W:((0#`;_hash 0#`);()) / (symbols;rules) w:{:[(#*w)>i:(w:*W)?x;W[1;i]:y;W::({(x;_hash x)}w[0],x;W[1],y)];} / define symbol v:{if[(#*w)>i:(w:*W)?x;W[1]:W[1]_di i;W[0;0]:w[0]_di i;W[0;1]:_hash*w]} / undefine symbol k:{[n;g;f;h;x;y]:[0~x;f;n>#x;(s[f;x];y);(((-n)_ x),,l[g;h;n;x];y)]} / k function l:{[g;h;n;x]:[~n;g[];n=1;g@*-1#x;f[g;h(-n)#x]]} / apply k function f:{[g;x]:[-3=4:x;{x[y]}/[g;x];g . x]} / f .".." vs f . x s:{[g;x]if[7=4:g;g:g[0;0]];:[#x;,x,g;,g]} / project on underflow x:{[n;f]{g:W[0;0]W[1]?;:[0~x;g _f;n>#x;(s[g _f;x];y);f[(-n)_ x;y].(-n)#x]}} / finite valence y:{[f]{:[0~x;W[0;0]W[1]?_f;f[x;y]]}} / infinite valence o:{[k;v;x;y]:[0~x;v;k;(x;v,y);(x,,v;y)]} / -> stack or queue m:{[p;x;y]i:#*p;n[p[0],();1_ p;i _ x;y;(i-:)#x]} / map pattern n:{[p;q;x;y;z](x;h[z;p;g[q;x]y],y)} / evaluate pattern g:{@[@[x;&x~'`"(";:[;y]];&x~'`")";:[;d z]]} / { <- x, } <- y h:{i[z;*{j[y]. x}/[(;x);y]]} / [template] + code i:{:[~@x;@[x;_n;_f;y];x _in!y;y x;x]} / dict -> list j:{:[~@x;(*{j[y]. x}/[(y;*z);x];1_ z);u x;(@[y;x;:;z];());(@[y;x;:;*z];1_ z)]} / list -> dict u:{{(x>64)&x<91}_ic*\$x} / upper case q:{f::[-3=4:x;=;~'];=/+\'(-1!~f[y]x 2)&/:(f[y]x 0;f[y]x 1)} / where not quoted / verbs (monad, dyad, commute) {w[`\$x,":"]k[1;. x,":";`\$x,":";::] w[`\$x]k[2;. x;`\$x;::] w[`\$x,"."]k[2;. x;`\$x,".";|:]}'"~!@#\$%^&*_-+=|<,>?.:"; / _x {w[`\$x]k[0;."{",x,"}";`\$x;:;]}'\$`_t`_T; {w[`\$x]k[1;. x;`\$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]k[2;. x;`\$x;::]}'"_",'\$`draw`in`lin`bin`binl`dv`di`dvl`sv`vs`sm`ss; w[`_ssr]k[3;_ssr;`_ssr;::] / n: {w[`\$x]k[2;. x;`\$x:(\$x),":";::] w[`\$x]k[2;. -1_ x;`\$x,:".";|:] w[`\$x]k[1;. x;`\$x:(-1_ x),":";::]}'!7; / literals ({w[`\$x]o[0;y]}'). L:(("_n";"0s";"0V";"0v";"0S";"0N";"0n";"0I";"-0I";"0i";"-0i") ( ;` ;!0 ;0#0.;0#` ;0N ;0n ;0I ;-0I ;0i ;0i )); / parse p:{ n:{ i:(!3)__ic"-.0123456789" j:(1 0 2;1 1 3;1 2 4;2 1 3;2 2 4;3 2 5;4 1 3;4 2 4;5 2 5) {.[x;(*y;i y 1);:;y 2]}/[6 256#0;j]} s:{(1(0 0 0;1 2 3;1 1 1;0 0 0)\(x="\\")+2*x="\"")?3} r:{:[3<1 n[]/_ic x;. x;`\$x]} b:" \n\r\t" c:"[]" P:{ :[~#y ;(x;y) (*y)_in b ;(x;1_ y) "//"~(*y),*1_ y ;(x;(y?"\n")_ y) "`"=*y ;@[_f[x;1_ y];0;,;`"`"] (*y)_in c ;(x,`\$*y;1_ y) "\\;"~(*y),*1_ y ;(x,`\$2#y;2_ y) "\\"=*y ;(x,`\$*y;1_ y) "'"=*y ;:["\\"=*1_ y;(x,."\"",y[1 2],"\"";3_ y);(x,y 1;2_ y)] "\""=*y ;(x,,"",. i#y;(i:1+s 1_ y)_ y) "{"=*y ;(x,`\$i#y;(i:1+q["{}\\";y]?1)_ y) (x,r i#y;(i:&/y?/:b,c)_ y)]} *(P .)/(();x,"")} / represent r:{ R:{:[(#*L)>i:L[1]?y ;L[0;i] (t:4:y)_in 1 2 ;5:y t=7 ;_f[1;y[_n;_n]],"`" x&t=-3 ;(","=*t)_ t:5:y t<1 ;{:[x;1!"][",y;y]}[x]1_,/" ",'_f[1]'y ((~x)&t=-3)|t=3 ;"'",1_-1_5:y t=5 ;(1!"][",,/_f[1]'. y)," .:" \$y]} :[#x,:"";R[0;x];x]} / eval, apply, shuffle, nest, trace e:{({if[T>0;t[x;y]];a[*y,();x,()](1_ y),()}.)/(x;y)} a:{:[(~#z)&_n~x;(y;z);x~`"[";{(x;d[z#y],z _ y)}[y;x,z;1+q[`\$'"[]\\";x,z]?1];(#**W)>i:W[0]?x;W[1;i][y;z];b[x;y]z]} b:{:[~4=4:x;(y,,x;z);~"{"=*a:\$x;(y,,x;z);c[1_'(2#&a=" ")_ a:" ",1_-1_ a;y;z]]} c:{m[(,d{:["[]"~x;();p@,/" ",'x]}x[0]_dv" "),d{p@,/@[y;_n;{:[~*y;x;y 1;" \\",x;" ",x]};+(y _lin x;q["[]\\"]y)]}. x;y]z} d:{*({:[~#z;(x;y;z);`"["~*z;(.[x;y;,;,()];y,#x . y;1_ z);`"]"~*z;(.[x;-1_ y;,;()];-1_ y;1_ z);(.[x;y;,;,*z];y;1_ z)]}.)/(();!0;x,())} t:{if[(#x)|#y;`0:(T\$r x)," : ",(-T)\$r y;:[#y;if[#0:`;T::0];`0:,""]]} / queue, stack w[`"->"] x[1]{[x;y;a](x;a,())} w[`"<-"] x[1]{[x;y;a](a,();y)} / cache, uncache (faster) w[`"=>"] x[1]{[x;y;a](x;y,,a)} w[`"<="] y{(x,-1#y;-1_ y)} / queue*, stack* w[`")"] y{(x,,d y;y)} w[`"("] y{(x,,x;y)} / use, mention w[`"/"] x[1]{[x;y;a](x;a,y)} w[`"\\"] y{(x,1#y;1_ y)} / enclose/disclose w[`"`"] x[1]{[x;y;a](x,,:[~@a;{y;a};7=4:a;a[_n;_n];a];y)} / define/undefine w[`";"] y{t:(i:y?`";")#y;:[1=#t;v@*t;w[*t]o[1;@[1_ t;&`"\\;"~'1_ t;:;`";"]]];(x;(i+1)_ y)} / amend, dmend w[`.a] x[3]{[x;y;a;b;c](x,,@[a;b;:;c];y)} w[`.d] x[3]{[x;y;a;b;c](x,,.[a;b;:;c];y)} / get, set w[`.s] x[2]{[x;y;a;b]w[`\$\$b]o[1;a];(x;y)} w[`.g] x[1]{[x;y;a](x,,:[(#**W)=i:W[0]?a:`\$\$a;a;W[1;i][0;0]];y)} / parse, represent w[`.p] x[1]{[x;y;a](x,,p a;y)} w[`.r] x[1]{[x;y;a](x,,r a;y)} / pointer-chasing (v/\i, j m/\i) w[`.v] x[2]{[x;y;i;v](x,,v/i;y)} w[`".v!"] x[2]{[x;y;i;v](x,,v\i;y)} w[`.m] x[3]{[x;y;j;i;m](x,,j m/i;y)} w[`".m!"] x[3]{[x;y;j;i;m](x,,j m\i;y)} / evaluate-alternate, xy w[`.ea] x[2]{[x;y;a;b]:[*r:.[e;(x;a,y);:];(x;b,y);r 1]} w[`.xy] x[2]{[x;y;X;Y]:[*r:.[a;(*Y;X,();(1_ Y),());:];'r 1;(x,r 1;y)]} / command, exit-to-k, exit, error, stop, trace, load, words w[`":cmd"] x[1]{[x;y;a]."\\",a;(x;y)} w[`":k"] y{.m[`r`p]:_n;(x;y)} w[`":exit"] y{y;_exit 0} w[`":error"] x[1]{[x;y;a]'a;(x;y)} w[`":stop"] y{`0;(x;y)} w[`":trace"] x[1]{[x;y;a]if[0 for next step, any character to exit"];(x;y)} w[`":load"] x[1]{[x;y;a]e[()]p{:[#i:_ss[x;"\r\n\\\\"];i[0]#x;x]}@6::["."_in a\$:;a;a,".xy"];(x;y)} w[`":words"] y{(x,,**W;y)} / run `0:,"XY 0.0 2005-07-23 Copyright (C) 2004-2005 Stevan Apter\n" S:();T:0 / stack, trace {e[()](x;`":load")}'(,"xy0.xy"),_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)&~T;`0:,r x]}S::*e[S]p x} / read-eval-print \ / cache, uncache (faster) w[`"=>"] x[1]{[x;y;a](x;y,,a)} w[`"<="] y{(x,,*-1#y;-1_ y)}