showstat(`convert/list`) ; `convert/list` := proc(a, expected_type::identical(`+`,`*`,`^`) := NULL, {nested::truefalse := false}, $) local i, j, dm; 1 if expected_type <> NULL then 2 if expected_type = `^` then 3 if not type(a,`^`) then 4 return [a, 1] end if elif not type(a,expected_type) then 5 return [a] end if; 6 return [op(a)] elif type(a,'rtable') then 7 if rtable_num_dims(a) = 0 then 8 return [] elif nested then 9 dm := [rtable_dims(a)]; 10 if nops(dm) = 1 then 11 return [seq(a[i],i = dm[1])] elif nops(dm) = 2 then 12 return [seq([seq(a[i,j],j = dm[2])],i = dm[1])] else 13 return convert_rtable_to_nested_list(a,1) end if else 14 try 15 return [seq(i,i = ArrayTools:-Alias(a,[ArrayTools:-NumElems(a)]))] catch : 16 return [seq(i,i = ArrayTools:-Reshape(a,ArrayTools:-NumElems(a)))] end try end if elif type(a,'array') then 17 return convert_old_array_to_list(a,nested) elif type(a,'table') then 18 if type([indices(a)],('list')(['integer'])) then 19 return [seq(eval(a[i],1),`in`(i,{indices(a,'nolist')}))] else 20 return [entries(a,'nolist')] end if elif type(a,'string') then 21 return StringTools:-Explode(a) elif type(a,'procedure') then 22 return convert(convert(a,'CompSeq'),list) elif type(a,('specfunc')('CompSeq')) then 23 return op(nops(a),a) elif type(a,'atomic') and not type(a,'`module`') then 24 return [a] else 25 return [op(a)] end if end proc