function mySet[]
- To: mathgroup at smc.vnet.net
- Subject: [mg36096] function mySet[]
- From: "Prof. Korvink" <korvink at informatik.uni-freiburg.de>
- Date: Wed, 21 Aug 2002 05:52:03 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I am struggling with a problem:
I would like to have a function mySet[] that takes a string argument
that is the correct string name of a "variable" and is able to
make assignments to that variable. Naively:
a = { 1, 2, 3, 4, 5 };
mySet[ s_String ] :=
Symbol[ s ] = { 2, 3, 4, 5, 6 }; (* ERRONEOUS! *)
mySet[ SymbolName[ a ] ];
a
should give:
{ 2, 3, 4, 5, 6 }
The problem is that Symbol[ s ] immediately evaluates to a List
and I cannot for the love of anything generate an expression that
evaluates to the actual unevaluated symbol.
I have tried many variants with HoldAll and so on, with no luck,
hopefully only out of ignorance.
What sometimes works (but circumstances is erratic!) is to do a:
mySet[ s_String ] :=
Evaluate[ToExpression[StringJoin[s,"={2,3,4,5,6}"]]]
I do not find this a clean way to do things. Can anyone offer some
insight and perhaps a solution?
Jan Korvink