MathGroup Archive 2007

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

Search the Archive

Re: Symbol name extraction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73712] Re: Symbol name extraction
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Mon, 26 Feb 2007 06:11:03 -0500 (EST)
  • References: <errlbu$83p$1@smc.vnet.net>

zac wrote:
> Dear Group,
> 
> 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?
> thanks in advance
> 
> Istvan Zachar
> 
> 
You have to stop your symbols being evaluated before you can access 
their names. The following code seems about the easiest:

SetAttributes[printSymbol, HoldAll];
SetAttributes[ps, HoldAll];
ps[x_] := Print[HoldForm[x], "=", x];
printSymbol[vars__] := Map[ps, Unevaluated[{vars}]]

Note that one problem with using SymbolName is that it will not 'notice' 
if the symbol is in a private context.

BTW, I often use the ps function (under another name) for debugging 
purposes.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Hold and Equal
  • Next by Date: Re: simple question
  • Previous by thread: Re: Symbol name extraction
  • Next by thread: Re: Symbol name extraction