I am stalled with the following problem: I want two lists, for example:
name={1,2,3}
and
namec={{1,2,3},{x,y,z},name}
The list "namec" is a list with extra information for internal use in a (non-comercial) package, while the List "name" is a vector shown to the user. The "name" inside the list has
Head[name]=String
I tried the following piece of code:
g = {1, 2, 3};
c = {x, y, z};
(ToExpression["Set[" <> # <> "c" <> ", {g,c," <> # <> "}]"];
ToExpression["Set[" <> # <> ", g]"]) &["name"];
the problem is that with the second assignment, the full list "name" replace the string "name" in the list "namec" (I know it could be a little confusing, this is counterintuitive to me). With the code above I get:
name={1,2,3}
and
namec={{1,2,3},{x,y,z},{1,2,3}}
Without the second assignment in the piece of code shown above, I get the list "namec" I want, however, the problem appears when I added the second assignment (name=g). Actually "name" is obtained interactively with an Input, but I simplified the code here. How can I solve this problem?, I suspect that I must use the Hold attribute but what I tried didn't work. Can somebody help me ?
Just for reference the real piece of code is:
With[{symbol = Input["enter a new name"]},
nom = ToString[symbol];
ToExpression[
"Set[" <> ToString[symbol] <> "c" <> ", {g,c," <>
ToString[symbol] <> "}]"];
ToExpression["Set[" <> ToString[symbol] <> ", g]"];
(* finally I get the solution based on a suggestion of george2079 (I only modified the last line of his solution) :*)
In[68]:= name = InputString["enter symbol name"]
ToExpression[name <> "={1,2,3}"]
ToExpression[name <> "c" <> "={{1,2,3},{x,y,z},name}"]
Out[68]= "ju"
Out[69]= {1, 2, 3}
Out[70]= {{1, 2, 3}, {x, y, z}, "ju"}
In[71]:= ju
Out[71]= {1, 2, 3}
In[72]:= juc
Out[72]= {{1, 2, 3}, {x, y, z}, "ju"}
Input[]
dialog. Would it be acceptable to enter it in quotes i.e."name"
, or use anInputField
? $\endgroup$