x={{a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}, {a[4], 0, 1}}
Table[Table[a[n], {n, 1, 4}], Evaluate[Sequence@@x]]==Table[Table[a[n], {n, 1, 4}], {a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}, {a[4], 0, 1}]
True
In the documentation for Table, in section "properties & relations" there is a subsection called "programmatic table construction" where one can find other ways to use a list to specify bounds for Table. For example :
Table[Table[a[n], {n, 1, 4}], ## ]&@@x==Table[Table[a[n], {n, 1, 4}], {a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}, {a[4], 0, 1}]
True
Edit:
How to use the errors to notice that x was not being evaluated
The error messages received might have been helpful as they showed that the list x was not being evaluated. Consider the following experiment:
x={i,4}
Table[i,x]
Error : Non-list iterator x at position 2 does not evaluate to a real numeric
value
Notice that the error says x and not the value of x which is {i,4} which might mean that x was not evaluated before the error happened. In that case we could try something even worse like
x=i
which we know leads to an error if we tried
Table[i,i]
Error : Non-list iterator i at position 2 does not evaluate to a real numeric
value.
But the error we receive if we use
Table[i,x]
is the same as the one before which mentions x instead of i.
Table[i,Evaluate[x]]
Gives the same error as Table[i,i]
and so refers to i instead of x and as expected Table[i,{i,4}] and
x={i,4};Table[i,Evaluate[x]]
works.
To summarize, as the error did not mention x it was a signal that Table might not be seeing how x is defined. In fact to highlight that the second argument was not evaluated before the error was given one can also try :
x={i,4};Table[i,x+1-1]
which shows :
Error : Non-list iterator x+1-1 at position 2 does not evaluate to a real
numeric value
Why doesn't Mathematica just evaluate the second argument ?
An experiment :
b=5;Table[b,{b,3}]
Does not give any errors. Why ? after all b=5 why is the output not the same as
Table[5,{5,3}]
Error : Raw object 5 cannot be used as an iterator
Well because b is not evaluated in Table as it holds its arguments. If it did not then one would have to think of all the symbols already used each time Table is called. In that case, what happens if we use Evaluate ? Would it create an error instead of solving one ?
a=5;Table[a,Evaluate[{a,3}]]
Error: Raw object 5 cannot be used as an iterator.
Output: Table[a, {5, 3}]
a=5;Table[Evaluate[a],{a,3}]
Guess the output
Summary: It is crucial that Table does not know how the variables are defined in the notebook until it is safe to do so, in particular until it has found the iterator (the variable that changes at each iteration).
Possible exercise: How would one go about making a homemade Table that computes table[g[h,u],{h,8}] in the light of the discussion above ?
x
in the second command? Could you, please, elaborate? $\endgroup$x
should be{a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}, {a[4], 0, 1}
. But all I have is the list{{a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}, {a[4], 0, 1}}
. $\endgroup$