abc:{ / cats, strengths, results s:`$'''$(),/:x a:`n`m`v`a j:,/s[;;1 2];k:,/l:s[;;0];i:,/a,\:/:a b:./[./[_n;i;:;-1];j;:;&#:'l] c:./[./[_n;i;:;`];j;:;k] (a;b;c)} S:(`nnn `vvv `nvn `nmn `mnv `vna`vva) / "result <- left right" @[_d;`A`B`C;:;abc S]; / cats, strengths, results type:{*(1<#:)(bind . drop@)/|@[x;&term'x;`n,1__f@]} / token-list -> parse-tree term:{:[1=#x;1;~atom x]} / nested token-list atom:{4:x 1} / (`type;"token") bind:{,/.[(0,y+0 2)_ x;1;pair;c . x[1 0+y;0]]} / ..xy.. -> ..(t;yx).. drop:{(x;:[&/=':k:b':*:'x;0;((&':n'-1_ x)|<':k)?1])} / drop in strength or n n .. pair:{,(y;|x)} / binding operation b:{:[` _in x,y;0;B[x;y]]} / syntax error strength c:{:[` _in x,y;`;C[x;y]]} / syntax error result n:`n~*: / noun? N:"0123456789" / digits E:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" / alpha P:"()" / parens Q:"\"\\`" / quote, escape V:"~!@#$%^&*=+|<,;>?" / verbs O:(*Q;" ";":";*P;P 1;".";"_";"-";N;V;"'/\\") / operators T:"q :",P,"._-0",,/$1_1!A / input types token:{[s] / string -> token-list f:_ci 255 / fill k:string s;s:*k;q:k 1 / a"xyz"b -> (a"b;"xyz") s:_ssr[;;" "]/[s;"\n\r\t"] / \n\r\t -> " " s:_ssr/[s;Q 2;" ",Q 2] / `a`b -> `a `b t:T(-1++\#:'O)_binl(,/O)?/:s / types t:_ssr[_ssr[t;"-.0";"nnn"]_ssr[;;"nn"]/("-0";".0");"0";"n"] / numbers t:_ssr[t;"-";"v"] / - t:t{_ssr[_ssr[_ssr[x;"n",y;"nn"];y,"n";"nn"];y;"v"]}/"._" / dot/dash notation t:t{_ssr[;y,"n";y,f]/x}/"n",f / nn -> n,f t:t{_ssr[x;y,":";y,f]}/(,/$1_ A),":" / o: -> o,f t[&t=":"]:"v" / : -> v i:&~t=" ";t@:i;s@:i / blank -> t:_ssr[t;P;"n",f] / P -> n p:&~t=f;t@:p;s:p _ s / x,f -> x i:&t="q";s[i]:q;t[i]:"n" / (a;"";b) -> (a;"xyz";b) k:symbol[s;t];s:*k;t:k 1 / ` "abc" -> `"abc" vector(+(`$'t;s))nest t} / nest, vectorize symbol:{[s;t] / extended symbols i:&{(Q[0]=*x)&y~,Q 2}':s:(,:'Q 2 0),s;t:" ",t / locate `" (1_,/{(,,/2#x),2_ x}'i _ s;1_ t _di i)} / nn -> n quote:{[s]b|~=\~b:(~-1!s=Q 1)&s=*Q} / mark quotations string:{[s] / represent strings q:s i@&j:(!#i:=+\~0=':quote s:" ",s)!2 / quotations s:i[;0]_ s;s[&j]:*Q;(1_,/s;q)} / replace quotations nest:{*{y . x}/[(();,0;0) / nest on P ({(x;@[-1_ y;-2+#y;+;1];z+1)} / P 1 {(.[x;-1_ y;,;z];@[y;-1+#y;+;1];z+1)} / x {(.[x;-1_ y;,;,!0];y,0;z+1)})1+-':0,depth x]} / P 0 depth:-/+\'P=\: / depth of P vector:{seq[sym]/seq[num]/@[x;&term'x;_f]} / vector notation seq:{:[1<#b:&(k#n),&\1,(k:n?1)_ n:&':x'y;fuse[y;b];y]} / ..nnn.. -> ..n.. fuse:{(y[0]#x),(,(`n;_ssr[1_,/" ",'x[y;1];" ",Q 2;Q 2])),(1+*|y)_ x} / fuse adjacent tokens num:{:[term x;0;lit x 1]} / numeric lit:{:[~|/x _lin N;0;(x[0]_in N,".-")&&/x _lin N,E,".-"]} / literal sym:{:[term x;0;x[1;0]=Q 2]} / symbolic parse:type token@ / parse lines:{:[atom x;(x 1;prim . x);line[*x;join@_f'x 1]]} / underline joined components prim:{dash[@[(#y)#"";(~y~P)*(y _lin P)?0;:;mark x];y]} / primitive: ..t .. dash:{@[x;(1+&/x?/:,/$A)_&&\~y=P 1;:;"\304"]} / primitive: ..t .. -> ..t__.. join:{next/x,'.[s;(;0);:;(|/c)-c:*:'s:^:'x]#'" "} / join successive diagrams next:{x,' :[|/((*|*x),**y)_lin(,/O)_dvl"._";y;" ",'y]} / join 2 diagrams line:{|.[.[|++y," ";0,,i;:;"\304"];0,*i:part y 0;:;mark x]} / underline diagram part:{(-b)_(b:P~|2#-1!x)_(*|depth x)_!#x} / fully parenthesized part mark:*|"^",$: / mark type group:{:[atom x;x;(*x;pe@_f'x 1)]} / essential () pe:{:[` _in x[;0];x;et . 1 0 pp'x;@[x;0;l r@];cn x 0;@[x;0;l r@];x]} / parenthesize expression et:{x&x=y} / equal vector-type cn:{:[atom x;0;`n=*x]} / complex noun l:{:[atom x;@[x;1;,;P 1];.[x;1;_f]]} / insert ( r:{:[atom x;@[x;1;P[0],];.[x;1 0;_f]]} / insert ) pp:{:[atom y;vt y;_f[x;y[1;x]]]} / left|right vector type vt:{:[~atom x;0;~`n=*x;0;num[x]|" "_in x 1;1;Q[2]_in x 1;2;0]} / vector type diagram:`0:lines group parse@ / diagram diagram s:"(+/'q*-(10 20 30+s))%/:(+/c)*/:t+s" \ thanks to christian langreiter for the 'nest' function dot notation: n. .n -> nn else nv vn dash notation: n_ _n -> nn else nv vn weak lists: a;b;c -> nvnvn, (a;b;c) -> a;b;,c null: () -> n null in list: a;();b verb in list: a;(+);b conjunctions: [] transforms {} vectors: numeric 10. 20 30.12 -> n symbol `a`b`c -> n some translations: a:b -> .(`a;();:;b) a[..;b;..] -> .(`a;(..;b;..)) a[..;b;..]:c -> .(`a;(..;b;..);(:);c) a[..;b;..]f:c -> .(`a;(..;b;..);f;c), (f) if f is a verb new adverbs?: f] f[ a f]:b = a f b (infix) a f[:b = b f a (commute)