Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: print variable name and its value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg100015] Re: [mg99979] print variable name and its value
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 21 May 2009 00:18:34 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

SetAttributes[dumpVar, {HoldAll, Listable}]

dumpVar[var_] :=
   Print[ToString[Unevaluated[var]], " = ", var];

myVar1 = 1;
myVar2 = 2;

dumpVar[myVar1];

myVar1 = 1

dumpVar[{myVar1, myVar2}];

myVar1 = 1

myVar2 = 2


Bob Hanlon

---- "Karsten W." <Karsten.G.Weinert at googlemail.com> wrote: 

=============
Hello,

how can I dump out a variable with its value? The following does not
work:

myVar1 = 1;
myVar2 = 2;
DumpVars[list_List] :=
  MapThread[(Print[#1, ": ", #2]) &, {Map[ToString[#] &,
     Unevaluated[list]], list}];

DumpVar[var_] := Print[ToString[Unevaluated[var]], ":", var];


DumpVars[{myVar1, myVar2}]
DumpVar[myVar1]

Any ideas?

Kind regards,
Karsten.



  • Prev by Date: Re: Wolfram|Alpha Lookup Tool for Mathematica
  • Next by Date: Legend for DateListPlot
  • Previous by thread: Re: print variable name and its value
  • Next by thread: Re: print variable name and its value