parsing rational integers with numericalio



Hi list,

I would like to know, what is the correct way to
parse the "/" from a read list of numbers in a file
with the numericalio package?

Thanks
Andre


The file looks as follows and describes a matrix

------------- readmatrix.txt -------------------
11 11
0 0 1/2
1 1 1/4
2 2 1/12
3 3 1/6
4 4 1/18
5 5 1/30
6 6 1/8
7 7 1/24
8 8 1/40
9 9 1/56
10 10 1/10
------------- readmatrix.txt -------------------

my finite state machine to parse the file with the MARKED line

------------- readmatrix.max -------------------
display2d : false;

load("numericalio");

matlist : read_list("./readmatrix.txt");

m : first(matlist); matlist : rest(matlist);
n : first(matlist); matlist : rest(matlist);

/* state 1: read i */
/* state 2: read j */
/* state 3: read numerator of A[i,j] */
/* state 4: read "\/" */
/* state 5: read denominator of A[i,j] */
/* state 6: process tuple (i,j,A[i,j]) */

lmatlist : length(matlist);
state : 1;
i : -1; j : -1; aij : false; h : false;
for kk : 1 thru lmatlist do block(
         if state = 1 then block(
                 i : first(matlist), matlist : rest(matlist),
                 state : 2
         ) else if state = 2 then block(
                 j : first(matlist), matlist : rest(matlist),
                 state : 3
         ) else if state = 3 then block(
                 aij : first(matlist), matlist : rest(matlist),
                 /* MARKED HACK */
                 if not numberp(first(matlist)) then block(
                         state : 4
                 ) else block(
                         state : 6
                 )
         ) else if state = 4 then block(
                 matlist : rest(matlist),
                 state : 5
         ) else if state = 5 then block(
                 aij : aij/first(matlist), matlist : rest(matlist),
                 state : 6
         ),

         if state = 6 then block(
                 print(i,j,aij),
                 state : 1
         )
);
------------- readmatrix.max -------------------