Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

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.
-------------------------------------------------------------


  • 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