Why do you use an empty character class? (This is the X column in your commented definition of sj).
If you got rid of this part of sj, you would not need fa and could define mj=: (a.&-.;<"0)',"''' Though, granted, this phrasing would need to be changed if you used non-default character classes with multiple members. But unless you are treating underspecified sequential machines, or a collection of them, "full generality" is probably not needed and is somewhat illusory. Generally speaking, sequential machines are not fully general. Thanks, -- Raul On Fri, May 24, 2013 at 11:57 AM, Zachary Elliott <[email protected]> wrote: > Porvided below is an example of using ;: for parsing CSV files. The > variable sj > is defined twice (once in the way I would normally define it in a script and > once in a more verbose manner for clarity) > > fa =. a. #~ # }. [: -. [: -. [: ~: a. ,~ ] > > sj =. 7 5 2 $ 0 0 1 1 2 1 3 1 4 1 0 0 1 0 2 2 1 0 1 0 0 0 1 1 1 2 3 1 4 1 0 > 0 3 0 3 0 5 0 3 0 0 0 4 0 4 0 4 0 6 0 0 0 0 0 2 2 3 0 0 0 0 0 0 0 2 2 0 0 4 > 0 > > sj =. _2] \"1 }.".;._2 (0 : 0) > NB. X C D Q S > 0 0 1 1 2 1 3 1 4 1 NB. 0 - Other > 0 0 1 0 2 2 1 0 1 0 NB. 1 - Char > 0 0 1 1 1 2 3 1 4 1 NB. 2 - Delim > 0 0 3 0 3 0 5 0 3 0 NB. 3 - Quote > 0 0 4 0 4 0 4 0 6 0 NB. 4 - SQuote > 0 0 0 0 2 2 3 0 0 0 NB. 5 - Second Quote > 0 0 0 0 2 2 0 0 4 0 NB. 6 - Second SQuote > ) > > mj =. <'';(fa ',"''');',';'"';'''' > > csv_parser =. (0;sj;mj)&;: > > csv_parser 'Year,"Make,Model",''foo,bar'',Hello,World' > ┌────┬────────────┬─────────┬─────┬─────┐ > │Year│"Make,Model"│'foo,bar'│Hello│World│ > └────┴────────────┴─────────┴─────┴─────┘ > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
