4

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
user8281
  • 151
  • 3

1 Answers1

4

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]
VF1
  • 4,702
  • 23
  • 31