// XY 2.0a 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)];} / W: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]} / W:undefine symbol u:{:[1=#x;v@*x;w[*x]o[1;@[1_ x;&Q[4]~'1_ x;:;Q[0;6]]]];(y;z)} / define/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);g x;(@[y;x;:;z];());(@[y;x;:;*z];1_ z)]} / list -> dict g:{{(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:{ :[~#y ;(x;y) (*y)_in b ;(x;1_ y) "//"~(*y),*1_ y ;(x;(y?"\n")_ y) ("`"=*y)&(*1_ y)_in 3#c ;(x,`\$2#y;2_ y) "`"=*y ;@[_f[x;1_ y];0;,;`"`"] (*y)_in 6#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+q 1_ y)_ 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, flat?, trace Q:(`"["`"`["`"("`"`("`"{"`"`{"`";";`"[["`"`[["`"(("`"`(("`"{{"`"`{{"`";;";`"]"`")"`"}"`";";`"\\";`"\\;") e:{({if[T>0;t[x;y]];a[*y,();x,()](1_ y),()}.)/(x;y)} a:{:[(~#z)&_n~x;(y;z);q[x]y;(y,,x;z);(#**W)>i:W[0]?x;W[1;i][y;z];(y,,x;z)]} q:{((~Q[0;6]~x)&Q[1;6]_in y)|(x _in V)&(~x _in,/Q 0 3)&(~x _in Q 2)&|/Q[1]_lin y} t:{if[(#x)|#y;`0:(T\$r x)," : ",(-T)\$r y;:[#y;if[#0:`;T::0];`0:,""]]} / quote, quote-function (flat) w[Q[0;0]] y{(x,Q[1;0];y)} w[Q[0;1]] y{(x,Q[1;1];y)} w[Q[2;0]] y{i:&/j:(|x)?/:Q[1;0 1];((-i+1)_ x;((,(-i)#x),:[>/j;`"`";()]),y)} / list, list-function (flat) w[Q[0;2]] y{(x,Q[1;2];y)} w[Q[0;3]] y{(x,Q[1;3];y)} w[Q[2;1]] y{i:&/j:(|x)?/:Q[1;2 3];((-i+1)_ x;(,(-i)#x;,`"/";`infra),:[>/j;`"`";()],y)} / pattern, pattern-function (flat) w[Q[0;4]] y{(x,Q[1;4];y)} w[Q[0;5]] y{(x,Q[1;5];y)} w[Q[2;2]] y{i:&/j:(|x)?/:Q[1;4 5];m[((-i)#x);(-i+1)_ x;:[>/j;`"`";()],y]} / define/undefine (flat) w[Q[0;6]] y{:[(#x)=i:(|x)?Q[1;6];(x,Q[1;6];y);u[(-i)#x;(-i+1)_ x]y]} / queue, stack w[`"->"] x[1]{[x;y;a](x;a,())} w[`"<-"] x[1]{[x;y;a](a,();y)} / use, mention w[`"/"] x[1]{[x;y;a](x;a,y)} w[`"\\"] y{(x,,*y;1_ y)} / enclose/disclose w[`"`"] x[1]{[x;y;a](x,,:[~@a;{y;a};7=4:a;a[_n;_n];a];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 2.0a (flat) 2005-07-16 Copyright (C) 2004-2005 Stevan Apter\n" S:();T:0 / stack, trace V:W[0;0] / primitives {e[()](x;`":load")}'(,"xy2.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