# Constructing an Array from typed expression

I want to produce an array from expressions given by

test[one][1] = 3;
.
.
test[one][5] = 7;


etc.

Normally would use Table[test[one][i], {i,N}], but for this you need the value of N that may not be known (without keeping track of it via some other means). I would like to be able to read the maximum value of the integer inside test[one][ ] and use this to construct the array. For expression such as test[1] = 5, this is straight forward since DownValues[test] can be used, but when adding another level the head becomes "test" and DownValues[] will not work.

The issue at hand is that curried values are stored in SubValues, not DownValues:

Do[test["one"][i] = Fibonacci[i], {i, 5}];
Last /@ SubValues[test]
(* {1, 1, 2, 3, 5} *)


If you have several definitions for test such as test["two"] or whatever, then you can pattern match on the SubValues:

Do[test["one"][i] = Fibonacci[i], {i, 5}];
Do[test["two"][i] = Fibonacci[i], {i, 6, 10}];
Cases[SubValues[test], x : test["two"][_] :> x, Infinity]

• Yes, thanks that's the function I was looking for – user8281 Aug 6 '13 at 3:50