How to fix this assignment list in math

I want to do the following in Mathematica

Table[p[i], {i, -3, 0}] = Flatten[{Table[0, {i, -3, -1}], 1}]

But I have an error:

Set::write: Tag Table in Table[p[i], {i, -3, 0}] is Protected.

However, this is wonderful.

{p[-3], p[-2], p[-1], p[0]} = Flatten[{Table[0, {i, -3, -1}], 1}]

Many thanks!

+3
source share
2 answers

Encourage the LHS to evaluate the parts that can be assigned:

Rate [Table [p [i], {i, -3, 0}]] = Flatten [{table [0, {i, -3, -1}], 1}]

+5
source

The reason it doesn't work is because it Sethas an attribute HoldFirst. This means that Set[a,stuff]passes the character ainstead of the value ain Set. As for this attribute, ask yourself: when you do Set[a,stuff], do you want to assign to a stuffsymbol aor value a?

a , , a HoldFirst . a , 5, a=stuff stuff a, 5

Hold :

Set@@{Table[p[i], {i, -3, 0}],Flatten[{Table[0, {i, -3, -1}], 1}]}
+4

Source: https://habr.com/ru/post/1784624/


All Articles