Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Symbols and Lists

  • To: mathgroup at
  • Subject: [mg39913] Re: Symbols and Lists
  • From: "Carl K. Woll" <carl at>
  • Date: Tue, 11 Mar 2003 02:38:29 -0500 (EST)
  • Sender: owner-wri-mathgroup at


The other responses work fine when the symbol in the list of symbols has no
value. However, if you assign a value to that symbol, and then later on you
want to assign a different value to the same symbol, then you are out of
luck with those approaches.

For example, the first time you run

Evaluate[ss[[3]]] = dd[[4]]

everything works nicely. But if you decide to assign a different value:

Evaluate[ss[[3]]] = dd[[5]]
Set::setraw: Cannot assign to raw object 7.

Now you get an error message, and ss[[3]] still has the value 7. A better
approach would be to get the symbol you want from ss without evaluating it,
and then to go ahead and give it a value. The following approach does this:

SetAttributes[partset, HoldFirst]
partset[l_, spec_, v_] :=
  Extract[OwnValues[l], Append[{1, 2}, spec], Hold] /. Hold[a_] :> =
Set[a, v]

I'm sure there is a cleaner approach, but the above will work. For example

partset[ss, 3, dd[[5]]]

and we see that initially ss[[3]] (or c) had the value 7 from what we did
above, but after the partset command ss[[3]] has the value abc.

Carl Woll
Physics Dept
U of Washington

"Goyder Dr HGD" <H.Goyder at> wrote in message
news:b4c8e4$n7k$1 at
> Dear MathGroup,
> I am doing something much more complicated but this trivial example
> expresses my difficulty.
> If I have a list of symbols and a list of data such as
> ss = {a, b, c, d, e}
> dd = {1, 5, {3, 4}, 7, abc, {0.1, 0.001}, 3.1415}
> how do I take a symbol from the list ss and associated it with data from the
> list dd?
> A wrong attempt is to try
> ss[[3]] = dd[[4]]
> This replaces element 3 in ss with element 4 from dd.
> What I need is an assignment so that, in this case, the symbol c is
> associated with the data. Equivalent to writing
> c = dd[[4]]
> so that c could then be used in subsequent expressions and the list ss is
> unchanged.
> Note that this is a trivial example for pedagogic purposes - I can't do
> simple assignment in my actual case.
> Thanks
> Hugh Goyder

  • Prev by Date: SetPrecision & Plot bug?
  • Next by Date: Re: Re: How to convert string to variable name
  • Previous by thread: Re: Symbols and Lists
  • Next by thread: RE: Re: Symbols and Lists