Re: Symbols, names, objects
- To: mathgroup at smc.vnet.net
 - Subject: [mg6537] Re: [mg6515] Symbols, names, objects
 - From: penny at suu.edu (Des Penny)
 - Date: Mon, 31 Mar 1997 23:01:36 -0500 (EST)
 - Sender: owner-wri-mathgroup at wolfram.com
 
>I need a function, let's call it Store, that takes two strings as
>arguments -- the NAMES of two variables the second ov which variables
>currently has some value -- and that causes the value in that variable
>to be assigned to the symbol.  (I don't care what the result returned
>by the function is; Null will do just fine.)  For example:
>
>    temp = {1, 2, 3};
>    Store["x", "temp"]
>
>After evaluating those expressions, the list {1,2,3} of numbers would
>be assigned to the variable x.
>
Hi:
Part of the problem is that the Set (i.e. = ) function has a HoldFirst
attribute. We must therefore force it to evaluate its first argument (i.e.
the left hand side of the =). The following will work:
Clear[store]
store[a_String,b_String]:=
( Clear[Evaluate[a]];
Set[Evaluate[ToExpression[a]],ToExpression[b]])
temp = {1, 2, 3};
store["x","temp"];
The variable x is now redefined:
x
gives
{1,2,3}
Hope this helps.
Cheers,
Des Penny
-------------------------------
Des Penny
Physical Science Dept.
Southern Utah University
Cedar City, UT 84720
VOICE: (Office): (801) 586-7708
       (Home)  : (801) 586-2286
FAX:    (801) 865-8051
e-mail: penny at suu.edu
-------------------------------