Re: Symbol name extraction
- To: mathgroup at smc.vnet.net
- Subject: [mg73729] Re: [mg73705] Symbol name extraction
- From: "厉正吉" <zhengji.li at gmail.com>
- Date: Tue, 27 Feb 2007 05:39:09 -0500 (EST)
- References: <200702250934.EAA08250@smc.vnet.net>
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.
-------------------------------------------------------------
- References:
- Symbol name extraction
- From: "zac" <replicatorzed@gmail.com>
- Symbol name extraction