# Renaming a list with name obtained interactively

I have a list say:

m = {1, 2, 3}


The list is inside a package, and is the result of a calculation. I want to give the user the option to rename it, for example with an input:

new = Input["enter a new name"]


I have not enough experience, but I tried in several ways and failed. The most obvious failure is to make:

new -> m


I cannot define new as a list prior to this assignment. On the other hand, I cannot define the name of a list as a vector with super-index or sub-index, for example:

v^i_; j = {1, 2, 3}


Can somebody help me?

-
because I want to rename m with a new name passed with the function Input. Thankx for prompt response. –  Gluoncito Jul 23 '13 at 20:48
@Nasser: thankx for your response, but it didnt work: I typed: In[1362]:= m = {1, 2, 3} Out[1362]= {1, 2, 3}; l = Input["enter name"]; l=m; Clear[m]; and then (new name is: lista): In[1396]:= lista Out[1396]= lista, –  Gluoncito Jul 23 '13 at 21:18

Do you want a Dialogbox that asks the user to input the name of a variable? It's late in the day for me but here's something crazy:

m = {1,2,3};

(Hold[(f = m)] /. f -> DialogInput[{name = ""}, Column[{"Type a name",
InputField[Dynamic[name], String], Button["Proceed", DialogReturn[Symbol@name],
ImageSize -> Automatic]}]]) // ReleaseHold


Entering test in the dialogbox should assign test = {1,2,3}.

-
perfect, it worked fine, I must learn more about Hold and Dynamic...Thankx a lot –  Gluoncito Jul 23 '13 at 21:31

The following works for me, but I'm not sure it's what you want.

myPkgm = {1, 2, 3};
newRef = ToString@Input["enter a new name"]


x[1]

ToExpression["Set[myPkg" <> newRef <> ", myPkgm]"];
myPkgx[1]


{1, 2, 3}

-
m_goldberg, thankx a lot, your approach also worked fine, in fact is nearest to what I am looking for. The list m is actually a contravariant vector v^i, on which I calculated the covariant derivative, so I must rename the resulting vector as v^i_;j, as I dont know how to include this characters (^i_;j) to the name of a symbol I must ask the user to rename the covariant derivative each time. But, this is fine for now. –  Gluoncito Jul 23 '13 at 22:04
@Gluoncito. Inside your package, have you tried using Subscript[Superscript[v, i], j] = m, where i, and j have appropriate integer values? –  m_goldberg Jul 23 '13 at 22:33
@Gluoncito. You might also use doubly-indexed variables such as v[2, 3], either in your package or entered into the "enter a new name" dialog. I think these are easier to deal with than nested Subscript and Superscript boxes. –  m_goldberg Jul 23 '13 at 22:55
@Gluoncito If m_goldberg's answer is "nearest to what [you] are looking for" feel free to un-accept mine and accept his. I was just thinking about Dialog boxes at the time you asked your question so I figured I'd shove a square peg in a round hole. –  bobthechemist Jul 24 '13 at 0:33
@m_goldberg: if I define the sub/superscripts with the command above, when the user types v^i_j he/she do not get the vector as an output, I tried, the user must type Subscript[Superscript[v, i], j] to get the vector. –  Gluoncito Jul 25 '13 at 3:24

I would do it like this:

With[{symbol = Input["enter a new name"]}, symbol = m]

-
Simon Woods; thankx it worked too, I'm just learning and migrating from fortran! –  Gluoncito Jul 23 '13 at 22:17
@Gluoncito, good luck! Mathematica's learning curve can be a bit steep to begin with, but it's worth it. Have you seen this question? It's got some really helpful stuff for new users. Item 4 of the "Basic Syntax Issues" answer might be particularly relevant - being able to use sub and superscripts seems like a really nice feature but most experienced users learn to avoid them. –  Simon Woods Jul 24 '13 at 9:38
thankx for the reference, I'd already read some books about mathematica the last week, but still I'm not confident with the more abstract syntaxis, however, thanks to this forum I am learning faster. –  Gluoncito Jul 25 '13 at 3:08