> parsing a csv file with 3 fields per record where any can be empty:
This is indeed an important application, and missing capability of ;:. discussion: https://code.jsoftware.com/wiki/User:Pascal_Jasmin/sequential_machine_intro A workaround to emit nulls part of jpp package (whole project must be loaded to use). https://github.com/Pascal-J/jpp/blob/master/fsm.ijs asserts at bottom show "preprocessing approach" for embedding null results. but an emit empty word code would be simpler/faster. On Monday, April 24, 2023 at 05:34:23 a.m. EDT, Danil Osipchuk <[email protected]> wrote: I wonder if I'm the only one bothered by semicolon's assertion of strictly i>j. Generally, empty words can be used as markers to impose some additional regularity on the output, to make it easier to process later. An obvious example would be parsing a csv file with 3 fields per record where any can be empty: ,, ,1st field, Is empty Full record, 3, "Hello, world" It is natural to parse it into empty strings where appropriate, but i>j gets into a way. Letting i>:j in and adding 3( for the sake of completeness) new opcodes like below seems to be increasing SM's usefulness considerably in mostly backwards compatible way. What do others think? 8 j=.i+1 9 j=.i+1 [ ew(i,j,r,c) 10 j=.i+1 [ ev(i,j,r,c) NB. Rows: 0: Waiting for terminating comma, 1: Inside of quotes NB. Columns: 0: comma, 1: double quotes, 2: other <"1 (2 3 2$ 0 9 1 1 0 0 1 0 0 0 1 0) +---+---+---+ |0 9|1 1|0 0| +---+---+---+ |1 0|0 0|1 0| +---+---+---+ csv =: (0;(2 3 2$ 0 9 1 1 0 0 1 0 0 0 1 0 );(',';'"');0 0 0 _1 ) & ;: csv ',,' ++++ |||| ++++ csv ',1st field, Is empty' ++---------+---------+ ||1st field| Is empty| ++---------+---------+ csv 'Full record, 3, "Hello, world"' +-----------+--+--------------+ |Full record| 3|"Hello, world"| +-----------+--+--------------+ ==== dlab:~/Sources/jsource-master/jsrc$ diff w.c w.c.orig 251c251 < #define CHKJ(j) ASSERT(BETWEENC((j),0,i),EVINDEX); --- > #define CHKJ(j) ASSERT(BETWEENO((j),0,i),EVINDEX); 272,274d271 < case 8: j=i+1; break; \ < case 9: if(0<=vi){EMIT(T,vj,vi,vr,vc); vi=vr=-1;} EMIT(T,j,i,r,c); j=i+1; break; \ < case 10: if(r!=vr){if(0<=vi)EMIT(T,vj,vi,vr,vc); vj=j; vr=r; vc=c;} vi=i; j=i+1; break; \ 339c336 < v=sv; DQ(p*q, k=*v++; e=*v++; ASSERT((UI)k<(UI)p&&(UI)e<=(UI)10,EVINDEX);); --- > v=sv; DQ(p*q, k=*v++; e=*v++; ASSERT((UI)k<(UI)p&&(UI)e<=(UI)7,EVINDEX);); 346c343 < if(2<=n){ijrd[1]=j=*v++; ASSERT(BETWEENC(j, -1, i),EVINDEX);} --- > if(2<=n){ijrd[1]=j=*v++; ASSERT(BETWEENO(j, -1, i),EVINDEX);} regards, Danil ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
