> showstat(`convert/list`); `convert/list` := proc(a) local i, j, u, l, rdims, rdimsdiff, rdimsorted, rdimplace; 1 if nargs = 1 then 2 if type(a,rtable) then 3 if rtable_num_dims(a) = 0 then 4 [] elif rtable_num_dims(a) = 1 then 5 return [seq(a[i],i = rtable_dims(a))] else 6 rdims := [rtable_dims(a)]; 7 rdimsdiff := [seq(rhs(rdims[i])-lhs(rdims[i]),i = 1 .. rtable_num_dims(a))]; 8 rdimsorted := sort(rdimsdiff); 9 if 0 < rdimsorted[-2] then 10 error "cannot convert rtable with more than one dimension having range greater than 0; try convert(A,listlist)" end if; 11 rdimplace := ListTools:-Search(rdimsorted[-1],rdimsdiff); 12 [seq(a[seq(rhs(rdims[i]),i = 1 .. rdimplace-1),j,seq(rhs(rdims[i]),i = rdimplace+1 .. nops(rdims))],j = lhs(rdims[rdimplace]) .. rhs(rdims[rdimplace]))] end if elif type(a,array) then 13 if type(a,name) and nops([op(2,eval(a))]) = 1 then 14 [seq(a[i],i = op(1,op(2,eval(a))) .. op(2,op(2,eval(a))))] elif not type(a,name) and nops([op(2,a)]) = 1 then 15 u := a; 16 l := [seq(u[i],i = op(1,op(2,a)) .. op(2,op(2,a)))]; 17 if has(l,'u') then 18 error "unassigned array elements" end if; 19 l else 20 error "can't convert array of dimension > 1" end if elif type(a,table) then 21 if type([indices(a)],('list')(['integer'])) then 22 map(x -> a[x],sort(map(op,[indices(a)]))) else 23 map(op,[entries(a)]) end if elif type(a,string) then 24 [seq(u,u = a)] elif type(a,procedure) then 25 convert(convert(a,'CompSeq'),list) elif type(a,('specfunc')('anything','CompSeq')) then 26 return op(nops(a),a) else 27 [op(a)] end if else 28 error "wrong number of arguments" end if end proc