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?

  • $\begingroup$ because I want to rename m with a new name passed with the function Input. Thankx for prompt response. $\endgroup$ – Gluoncito Jul 23 '13 at 20:48
  • $\begingroup$ @Nasser: thankx for your response, but it didn`t 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, $\endgroup$ – 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}.

|improve this answer|||||
  • $\begingroup$ perfect, it worked fine, I must learn more about Hold and Dynamic...Thankx a lot $\endgroup$ – Gluoncito Jul 23 '13 at 21:31

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

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


ToExpression["Set[myPkg`" <> newRef <> ", myPkg`m]"];

{1, 2, 3}

|improve this answer|||||
  • $\begingroup$ 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 don`t 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. $\endgroup$ – Gluoncito Jul 23 '13 at 22:04
  • $\begingroup$ @Gluoncito. Inside your package, have you tried using Subscript[Superscript[v, i], j] = m, where i, and j have appropriate integer values? $\endgroup$ – m_goldberg Jul 23 '13 at 22:33
  • $\begingroup$ @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. $\endgroup$ – m_goldberg Jul 23 '13 at 22:55
  • 1
    $\begingroup$ @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. $\endgroup$ – bobthechemist Jul 24 '13 at 0:33
  • $\begingroup$ @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. $\endgroup$ – Gluoncito Jul 25 '13 at 3:24

I would do it like this:

With[{symbol = Input["enter a new name"]}, symbol = m]
|improve this answer|||||
  • $\begingroup$ Simon Woods; thankx it worked too, I'm just learning and migrating from fortran! $\endgroup$ – Gluoncito Jul 23 '13 at 22:17
  • $\begingroup$ @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. $\endgroup$ – Simon Woods Jul 24 '13 at 9:38
  • $\begingroup$ 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. $\endgroup$ – Gluoncito Jul 25 '13 at 3:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.