       Re: Printing Variables and Their Values

• To: mathgroup at smc.vnet.net
• Subject: [mg46420] Re: [mg46410] Printing Variables and Their Values
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Tue, 17 Feb 2004 07:05:51 -0500 (EST)
• References: <200402170443.XAA28642@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On 17 Feb 2004, at 05:43, Bruce W. Colletti wrote:

>
> Re Mathematica 5.0.1.
>
> For a list of variables, how would I successively print each variable's
> name followed by its value?
>
> For instance, when x = 7, y = 5 and z = 4, feed list {x,y,z} into
> a function that prints "x = 7, y = 5, z = 4."
>
> Although Print["x = ", x, "  y = ", y, "  z = ", z] works, I want
> to automate this for any list.
>
> Thanks.
>
> Bruce
>
>
>

The first question is how you want to pass the names of the variables
to your function. I suggest using Hold[variables]. So here is one way
to do this:

VariableValues[l_Hold] := StringReplace[ToString /@
(Flatten[{ReleaseHold[Map[OwnValues, l]]}] /. {HoldPattern ->
HoldForm}),
":>" -> "="]

In:=
{x,y,z}={1,2,3};

In:=
VariableValues[Hold[x,y,z]]

Out=
{x = 1,y = 2,z = 3}

Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/

```

• Prev by Date: Re: Equal, Inequality and TraditionalForm
• Next by Date: RE:
• Previous by thread: Printing Variables and Their Values
• Next by thread: Re: Printing Variables and Their Values