// XY 1.7 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]:[(#x) _z c:{i[z;*{j[y]. x}/[(;x);y]]} / [template] + code d:{@[z;&h z;{:[~@z;@[z;&h z;_f[x;y]];z~`_x;x;z~`_y;y;z]}[x;y]]} / stack -> _x, queue -> _y h:{:[#x;~>/+\'(~0,-1_ x~\:`"\\")&/:x~'/:`\$'"{}";!0]} / not within live braces i:{:[~@x;@[x;&h x;_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} / initial upper-case? / 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]} q:{(1(0 0 0;1 2 3;1 1 1;0 0 0)\(x="\\")+2*x="\"")?3} s:{:[~1=#i:_ss[x;"--"];`\$x;`"{",(,t i#x),((t:{p _ssr/[,/" ",'x;"<>";"[]"]})(2+i*:)_ x),`"}"]} r:{:[3<1 n[]/_ic x;. x;s x]} b:" \n\r\t" c:"[]()\"" P:{[x;y;z;w] :[~#z ;(x;y;z;w) (*z)_in b ;(x;y;1_ z;w) "//"~(*z),*1_ z ;(x;y;(z?"\n")_ z;w) "`["~(*z),*1_ z ;(.[x;y;,;,()];y,#x . y;2_ z;w,1) "`("~(*z),*1_ z ;(.[x;y;,;,,()];y,(#x . y),0;2_ z;w,1) "`"=*z ;@[_f[x;y;1_ z;w];0;,;`"`"] "["=*z ;(.[x;y;,;,()];y,#x . y;1_ z;w,0) "]"=*z ;(.[x;-1_ y;,;:[*-1#w;`"`";()]];-1_ y;1_ z;-1_ w) "("=*z ;(.[x;y;,;,,()];y,(#x . y),0;1_ z;w,0) ")"=*z ;(.[x;-2_ y;,;(,`"/";`infra),:[*-1#w;`"`";()]];-2_ y;1_ z;-1_ w) "\\;"~(*z),*1_ z ;(.[x;y;,;`\$2#z];y;2_ z;w) "\\"=*z ;(.[x;y;,;`"\\"];y;1_ z;w) "'"=*z ;:["\\"=*1_ z;(.[x;y;,;."\"",z[1 2],"\""];y;3_ z;w);(.[x;y;,;z 1];y;2_ z;w)] "\""=*z ;(.[x;y;,;,"",. i#z];y;(i:1+q 1_ z)_ z;w) (.[x;y;,;r i#z];y;(i:&/z?/:b,c)_ z;w)]} *(P .)/(();!0;x,"";!0)} / 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, trace e:{({if[T>0;t[x;y]];a[*y,();x,()](1_ y),()}.)/(x;y)} a:{:[(~#z)&_n~x;(y;z);(#**W)>i:W[0]?x;W[1;i][y;z];(y,,x;z)]} 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)} / use, mention w[`"/"] x[1]{[x;y;a](x;a,y)} w[`"\\"] y{(x,1#y;1_ y)} / patterns w[`"{"] y{:[~i:(b[1]& 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 1.7 2005-07-23 Copyright (C) 2004-2005 Stevan Apter\n" S:();T:0 / stack, trace {e[()](x;`":load")}'(,"xy.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