Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
Related: (9440); Documentation on different *Values types. –  Mr.Wizard Aug 6 '13 at 6:14

1 Answer 1

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]
share|improve this answer
    
Yes, thanks that's the function I was looking for –  user8281 Aug 6 '13 at 3:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.