MathGroup Archive 2007

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

Search the Archive

Re: Symbol name extraction


Dear Zachar,

Here we are.

a = "x";
b = 0;
c = {1, 2, 3};

SetAttributes[MySymName, HoldAll];
MySymName[sym_] := SymbolName@Unevaluated@sym;
SetAttributes[ExpToStr, HoldAll];
ExpToStr[sym_] := (MySymName[sym] <> " = " <> ToString[sym] <> ";\n");

(* ATTENTION: Change the attributs of Map !! *)
SetAttributes[Map, HoldRest];

Remove[printSymbol];
SetAttributes[printSymbol, HoldAll];
printSymbol[vars__] := StringJoin @@ (ExpToStr /@ {vars});


printSymbol[a, b, c] // InputForm

On 2/25/07, zac <replicatorzed at gmail.com> 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
>

-- 
Li Zhengji
-------------------------------------------------------------
If all you have is a hammer, everything is a nail.
-------------------------------------------------------------


  • Prev by Date: curious results form Integrate
  • Next by Date: disable SyntaxQ beep
  • Previous by thread: Symbol name extraction
  • Next by thread: Re: Symbol name extraction