This question already has an answer here:

read some related posts and found no solution. For a list defined like this

m = {0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1.0, 1.5, 1.6};

when I define this function

f[m__] :=m[[Range[2, Length[Evaluate[m]], 1]]] = {{r, x, y, u, v, n, l, w, 
  s}, m[[Range[2, Length[Evaluate[m]], 1]]]}\[Transpose];

I get an error telling me the list in the part assignment is not a symbol.

I want to be able to build a function that does the operation on different lists and takes the name of the list as an argument.


marked as duplicate by Lukas Lang, MarcoB, m_goldberg, Alex Trounev, WReach May 12 at 5:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Please explain what are you trying to do. what is f supposed to do? $\endgroup$ – Kuba May 8 at 8:37
  • $\begingroup$ I'd venture m = Transpose[{{r, x, y, u, v, n, l, w, s}, Rest@m}] will accomplish what it appears you're after... $\endgroup$ – ciao May 8 at 8:49
  • $\begingroup$ Or, maybe m[[2 ;;]] = Transpose[{{r, x, y, u, v, n, l, w, s}, m[[2 ;;]]}] is what you are trying to do. $\endgroup$ – LouisB May 8 at 9:21
  • $\begingroup$ Take a look at Hold and evaluation control in general - the Evaluate is not needed in this case for example. The error stems from the fact that m is evaluated to a list before it's passed to f, which causes Part to complain $\endgroup$ – Lukas Lang May 8 at 11:54
  • 3
    $\begingroup$ Possible duplicate of How to modify function argument? - See also Modifying parameters: Set::setps in the part assignment is not a symbol $\endgroup$ – Lukas Lang May 8 at 11:56
f2[list_] := Transpose[{{r, x, y, u, v, n, l, w, s}, list[[2 ;;]]}]


{{r, 0.3}, {x, 0.4}, {y, 0.5}, {u, 0.6}, {v, 0.7}, {n, 0.9}, {l, 1.}, {w, 1.5}, {s, 1.6}}


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