MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Symbol name extraction

  • To: mathgroup at
  • Subject: [mg73718] Re: Symbol name extraction
  • From: albert <awnl at>
  • Date: Mon, 26 Feb 2007 06:14:19 -0500 (EST)
  • References: <errlbu$83p$>


> I have to write a list of parameters to a file, in string format.
> In the first shot, I've tried something like this:
> a = "x";
> b = 0;
> c = {1, 2, 3};
> printSymbol[vars__] :=StringJoin[Map[(SymbolName[#] <> " = " <>
> FullForm[#] <>";\n") &, {vars}]];
> printSymbol[a, b, c]
> but it fails to recognize symbol names. Any suggestion?

What you want to achieve is not completly trivial, since you have to take
care that a, b and c are not evaluated before SymbolName sees them. The
following is one way to achieve what you need, there are of course several

In[1]:= ClearAll[printSymbol]
In[2]:= SetAttributes[printSymbol,HoldAll]
In[3]:= printSymbol[var_Symbol]:=StringJoin[
         SymbolName[Unevaluated[var]]," = ",ToString[InputForm[var]],";\n"
In[4]:= printSymbol[vars_List]:=StringJoin[
In[5]:= printSymbol[{a,b,c}]
a = "x";
b = 43;
c = {1, 2, 3};

anyway, have you looked at the function Save? I think it does the same thing
and writes the resulting string to a file. It is probably more efficient
and secure than whatever you can achieve. Just try:


and see whether that fits your needs.



  • Prev by Date: Re: showing an expression equal to 0
  • Next by Date: Re: PolyLog help
  • Previous by thread: Re: Symbol name extraction
  • Next by thread: Re: Symbol name extraction