|
[Date Index]
[Thread Index]
[Author Index]
Re: print variable name and its value
- To: mathgroup at smc.vnet.net
- Subject: [mg99992] Re: print variable name and its value
- From: dh <dh at metrohm.com>
- Date: Thu, 21 May 2009 00:06:58 -0400 (EDT)
- References: <gv0ius$b8v$1@smc.vnet.net>
Hi Karsten,
Mathematica tries to evaluate every expression if possible. By default,
a function gets bits arguments only after they are evaluated. To prevent
this, you must specify the attribute HoldAll or HoldFirst.
Further inside the function you muast again take care that the
expression is not evaluated.
=================================
myVar1 = 1;
myVar2 = 2;
SetAttributes[DumpVars, HoldAll];
DumpVars[d_List] :=
Function[{x}, Print[HoldForm[x], "= ", x],
HoldAll] /@ (Unevaluated@d);
DumpVars[{myVar1, myVar2}]
==============================
Daniel
Karsten W. 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:
Rotating a list of 3D point coordinates in one shot
Next by Date:
Solving integral equations numerically
Previous by thread:
Re: print variable name and its value
Next by thread:
100000 messages to MathGroup and a rose to the Moderator
|