MathGroup Archive 2004

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

Search the Archive

RE: Printing Variables and Their Values

  • To: mathgroup at
  • Subject: [mg46418] RE: Printing Variables and Their Values
  • From: "David Park" <djmp at>
  • Date: Tue, 17 Feb 2004 07:05:49 -0500 (EST)
  • Sender: owner-wri-mathgroup at


It's probably a matter of style, but I wouldn't do it that way.

First I would hardly ever write a statement like x = 7 unless I had a
Clear[x] in the same Cell. Single letter symbols are just too often used as
pure symbols and the most common error is to set values for them and then
forget that you did that.

I would set up the data as a set of substitution rules.

(data = {a -> 1, b -> 2, c -> 3, x -> 7, y -> 5, z -> 4}) // TableForm

Then you can perform all the algebraic manipulations you want and substitute
the data at any point without destroying your ability to use x,y,z etc., as

To display a limited set of values you could use...

displayvalues[symbols___] :=
  Thread[{symbols} == ({symbols} /. data)] // TableForm

displayvalues[a, c, x, z]

Or if you want to print the data across a line you could use

printvalues[symbols___] :=
  MapAt[Drop[#, -1] &,
    Inner[SequenceForm[ToString[#1] <> " = ", #2,
          ",  "] &, {symbols}, {symbols} /. data, SequenceForm], -1]

printvalues[x, y, z]

The Inner statement is always a nice way to combine two equal length lists,
in this case the symbols and the symbol values. The Drop statement was
needed to get rid of the comma and space on the last value.

David Park
djmp at

From: Bruce W. Colletti [mailto:bcolletti at]
To: mathgroup at

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.



  • Prev by Date: Re: how to read this data file in mathematica?
  • Next by Date: RE: Printing Variables and Their Values
  • Previous by thread: Re: Printing Variables and Their Values
  • Next by thread: RE: Printing Variables and Their Values