Rather than using FoldList, this seems to be a perfect application of recursion and memoization, which leads to a very elegant solution:
(* Your original list *)
list[1] = {1, 2, 3};
list[2] = {7, 8, 9};
list[3] = {15, 20, 22};
(* The cumulative list *)
cumulativeList[0] = {};
cumulativeList[n_] := cumulativeList[n] = cumulativeList[n - 1] ~Join~ list[n]
Now you just need to evaluate cumulativeList[3] and automatically, all the other values (i.e. 1, 2) are calculated.
cumulativeList[3]
(* {1, 2, 3, 7, 8, 9, 15, 20, 22} *)
Table[cumulativeList[n], {n, 3}]
(* {{1, 2, 3}, {1, 2, 3, 7, 8, 9}, {1, 2, 3, 7, 8, 9, 15, 20, 22}} *)
FoldListwithJoinfor this? It will work! :) – Theo Tiger Jul 01 '13 at 10:28Listis. It will cause collisions, as in this case. – C. E. Jul 01 '13 at 10:32AccumulatewithJoininstead ofSum. And you can useFoldList. So have a look at the documentation forAccumulate, it says:Accumulate[list]is effectively equivalent toRest[FoldList[Plus,0,list]]. So there you go! TryRest[FoldList[Join,{},list]]. – Theo Tiger Jul 01 '13 at 11:40listandcumulativeListbe regularLists? So, is list actuallylist = {{1,2,3},{7,8,9},{15,20,22}}or is list just a Symbol (as suggested by the code you have pasted)? If you are unsure, let me suggest that{{1,2,3},{7,8,9},{15,20,22}}is what you want. – Theo Tiger Jul 01 '13 at 12:33Listby doinglist[1]=...but merely assigning values to a symbol?[]associates values to symbols. In contrast,[[]]refers to list indices. In the title you wrote that you have a list of lists, and that would belist={{1,2,3}..}as mentioned in the comment above. Since the answers so far do not deal with list actually being aList, this is a question to think about first. – Theo Tiger Jul 01 '13 at 12:47list[1] = {1, 2, 3};list[2] = {7, 8, 9};list[3] = {15, 20, 22};is not the same as doinglist={{1,2,3},{7,8,9},{15,20,22}}? – andre314 Jul 01 '13 at 13:56