Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Re: Can't assign value to symbols

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58458] Re: [mg58444] Re: [mg58409] Can't assign value to symbols
  • From: Andrzej Kozlowski <akozlowski at gmail.com>
  • Date: Sun, 3 Jul 2005 03:57:11 -0400 (EDT)
  • References: <200507020807.EAA01689@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Instead of ToExpression use

ToExpression[#, StandardForm, Unevaluated] &

For example:


In[1]:=
parameters = {{"a", "b", "c"}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

In[2]:=
MapThread[(#1 = #2) & , {ToExpression[#,StandardForm,Unevaluated]& /@
parameters[[1]],
parameters[[3]]}] ;

In[3]:=
a

Out[3]=
4

In[4]:=
MapThread[(#1 = #2) & , {ToExpression[#,StandardForm,Unevaluated]& /@
parameters[[1]],
parameters[[2]]}] ;

In[5]:=
a

Out[5]=
1


Of course instead of Standardform you can use TraditionalForm or even  
InputForm.

Andrzej Kozlowski

Chiba, Japan


On 2 Jul 2005, at 17:07, Lee Newman wrote:

> Thanks for the solutions.  I'm running with David Park's solution, but
> now realize there is one additional problem.  Once I've executed the
> statement  MapThread[(#1 = #2) & , {parameters[[1]], parameters 
> [[3]]}] ,
> because I've specified the first row of "parameters" as symbols, this
> row now loses the symbol names and takes on the assigned values, such
> that my attempt to execute the MapThread Statement again for a  
> different
> set of values, e.g. parameters[[2]], fails.
>
> in: MapThread[(#1 = #2) & , {parameters[[1]], parameters[[3]]}] ;
> in: {a,b,c}
> Out: {4,5,6}
> in: MapThread[(#1 = #2) & , {parameters[[1]], parameters[[2]]}] ;
> out:  Set:: setraw : Cannot assign to raw object 4 ...  etc
>
> I want to preserve the first row of "parameters" as the symbol  
> names, so
> one solution is to use strings, and modify David Park's solution to  
> turn
> the strings into symbol names when assigned, This works the first time
> it is run, and parameters[[1]] still contains the strings, but ut  
> still
> fails the second time.  but why?
> in:  parameters = {{"a", "b", "c"}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
> in:  MapThread[(#1 = #2) & , {ToExpression /@ parameters[[1]],
> parameters[[3]]}] ;
> in:  {a,b,c}
> out {4,5,6}
> in:  MapThread[(#1 = #2) & , {ToExpression /@ parameters[[1]],
> parameters[[3]]}] ;
> out:   Set:: setraw : Cannot assign to raw object 4 ...  etc
>
> why does the MapThread statement fail the second time?  It seems
> ToExpression/@parameters[[1]] converts the strings "a", "b", "c" to
> symbols but then evaluates them prior to returning them, so the  
> attempt
> to assign to them in MapThread fails.
>
> How can I modify the MapThread statement so I can call it multiple
> times, each time assigning values to the symbols identified by the
> strings in the first row??
>
> Lee
>
>
>
> David Park wrote:
>
>> Lee,
>>
>> Set (=) has a higher precedence Than Function (&). So all you have  
>> to do is
>> add parentheses.
>>
>> parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
>>
>> MapThread[(#1 = #2) & , {parameters[[1]], parameters[[3]]}]
>> {4, 5, 6}
>>
>> David Park
>> djmp at earthlink.net
>> http://home.earthlink.net/~djmp/
>>
>> From: Lee Newman [mailto:leenewm at umich.edu]
To: mathgroup at smc.vnet.net
>>
>>
>> Hello,
>>
>> Situation:  I have a table that contains parameters and sets of  
>> values
>> that I want to assign to the parameters for the purposes of running a
>> simulation.
>> - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}}
>> - want to assign values in a given row to the symbols listed in the
>> first row.
>> - tried using:  MapThread[  #1 = #2 &, {parameters[[1]], parameters 
>> [[3]]} ]
>> - fails with error  "Tag Slot in #1 is Protected"
>> - tried adding Unprotect[#1] and a variety of other attemps, but  
>> can't
>> get it to work.
>>
>> Anyone know how might accomplish this?
>>
>> Thanks,
>> Lee
>>
>>
>>
>
>
>
>


  • Prev by Date: Re: Can't assign value to symbols
  • Next by Date: Re: Integrate and Boole problems
  • Previous by thread: Re: Can't assign value to symbols
  • Next by thread: Re: Re: Can't assign value to symbols