I'm trying to do something like this:
test = {x, y};
With[{test[[1]] = 3}, x/y]
However, the following error is printed:
With::lvset: "Local variable specification {test[[1]]=3} contains test[[1]]=3, which is an assignment to test[[1]]; only assignments to symbols are allowed"
I'm assuming this is because Mathematica treats the list elements as expressions and not as symbols correct? Setting x
directly works, but I need the index for a loop functionality. Any hint on how to force Mathematica to interpret test[[1]]
as a symbol?
With[{# = 3}, x/y] &[test[[1]]]
ifx
has no value. $\endgroup$With
has attributeHoldAll
hencetest[[1]]
isn't evaluated tox
prior to trying to make the assignment. $\endgroup$With
is the problem. Set isHoldFirst
too. $\endgroup$