// The code is difficult to read; // feels like there is a lot of scalar indexing code, but perhaps not // Every function should have a comment describing it // and ideally illusrate a simple input and output // Every variable which isn't obvious should be described by a comment // such as \\ c is circumference of a cirlce radius r // Given SS are described as sheet of rows by cols of cells likely sheet or cells is a better name // than table? // Functions which are long should be split as separate statements \d u // What is this??? \l utils.k \d csv // what is this if comment those things which people may not know if not on the same line on a previous line \l ngnk-libs/csv/csv.k \d . \l excelpm.k // what functions are you using \d . /helpers can describe them in comments here or have comment with each helper / e exclusive // what is "exclusive" slice: {[l;s;e] s_(e)#l}; / brief comment listize: {1_(,/(";",)'{"(",x,")"}'x)}; // brief comment split: {[l;di] idx: (-1,&(di~'l)),(#l); // brief comment {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))}; // brief comment s2n: {[s] `i$s;}; // string to number` parseidx: {core: slice[x;1;#x]; split[core;";"]}; // brief comment what is core? gi: {[r;c;rb;cb] // what is gi? rb, cb i: r#(,!c) i: ((!r)+rb) {x,'y}'(i+cb); :i }; // brief comment I don't think functions require a closing ; unless ngnk does? // decode excel formula mc: {[c;i] // brief comment i: gi[(#table);i+1;0;c]; :i }; mr: {[r;i] // brief comment i: gi[i+1;(#table[0]);r;0]; :i }; drr: {[s;e] // brief comment r: $[s[0]<0;mc[s[1];(e[1]-s[1])];mr[s[0];(e[0]-s[0])]]; :r }; dre: {[s;e] // brief comment :gi[(e[0]-s[0])+1;(e[1]-s[1])+1;s[0];s[1]] }; dr: {[s;e] // decode range ln: (s[0]<0) | (s[1]<0); rn: (e[0]<0) | (e[1]<0); :$[ln|rn;drr[s;e];dre[s;e]] // brief comment }; dbit: {[b] // brief comment ci: (`i$(b@&(pat.testAtZ'b)))-65; // col index ri: (`i$(b@&(pat.test0t9'b)))-49; // row index ci: $[(#ci)>0;*ci;-1]; ri: $[(#ri)>0;*ri;-1]; :(ri;ci) }; lr: {[f] // brief comment ci: *&(":"~'f); l: slice[f;0;ci]; r: slice[f;ci+1;#f]; lb: dbit[l]; rb: dbit[r]; :(lb;rb); }; de:{[idx;cell] // brief comment ci: cell[0]; cell: cell[1]; idx: (*idx); // what is ix f: slice[cell;idx[0];idx[1]]; // What is f l: slice[cell;0;idx[0]]; // What is l r: slice[cell;idx[1];#cell]; u.ppr (l;r); // what is u.ppr u.ppr table[ci[0];ci[1]]; (fl;fr): lr[f]; // brief comment r: dr[fl;fr]; i: (ci[0]*3) + ci[1]; { i:(*y); i: (i[0]*3)+i[1]; deps[x;i]: 1; }[(ci[0]*3)+ci[1];]'r; }; // brief comment /:parseidx["[1;2]"]; /:split["1;2;3";";"]; tstkey: "States/Events"; / key indicating start of transition section // SS dpn't have States/Events" cstkey: "Events"; / key indicating start of events condition section astkey: "Actions"; / key indicating start of actions section sectionkeys: (tstkey;cstkey;astkey); lines: {x,"\n",y}/(0: "SS.csv"); table:: csv.csv[lines]; d: (#table)*(#table[0]); deps:: (d;d)#0; / brief comment / excel patterns :pats: pat.run''table; u.ppr'table; / u.ppr'pats; // start with last to maintain prior index accuracy lasts:{:((#x[0])-1)_x[0]}''pats; firsts:{:$[(#x[0])>1;((#x[0])-1)#x[0];0]}''pats; f: pats { :$[x[2]=5;y;0] }''lasts; ti: gi[#table;#table[0];0;0]; table::ti {(,x),,y}''table; table { :$[y~0;0;de[y;x]] }''f; // brief comment table { :$[y~0;0;de[y;x]] }''firsts; // brief comment