MathGroup Archive 2009

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

Search the Archive

Re: problem writing debugging utility function

  • To: mathgroup at
  • Subject: [mg100293] Re: problem writing debugging utility function
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at>
  • Date: Sun, 31 May 2009 06:34:46 -0400 (EDT)
  • References: <gvq09k$mqv$>

SetAttributes[printVariable, HoldAll];
printVariable[var_] := Print[ToString[HoldForm[var]] <> " = " <>

ape = 1;

Out: ape = 1

Cheers -- Sjoerd

On May 30, 2:57 am, "dabro... at" <dabro... at>
> This matter is pretty unimportant, but perhaps of interest in laying
> out a persistent source confusion for me with Mathematica: evaluation
> control.
> I'm skeptical of the built-in debugger because it seems to crash the
> kernel often, so I do most of my debugging by inserting print
> statements like
>     Print["variableOne = ",variableOne].
> Being extraordinarily lazy I soon thought it might be nice to have a
> little function, say dbgv, which takes a variable or name of a
> variable as an argument, and produces the same result as the print
> statement above.
> At first I assumed this would be easy, since almost every programming
> problem turns out to be pretty easy with Mathematica.  But after an hou=
> or so I began to wonder whether it would be possible at all.  I did
> eventually find a solution, a function dbgv such that dbgv[variableOne]
> produces exactly the effect of the print statement, but it's really ugly.
> I'll post it later.
> Granted this is not an important problem since it's not too much
> trouble to just type in the whole print statement.  But it's worth
> noting that this would trivial to solve with a Lisp macro, and despite
> the fantastic expressibility of Mathematica it doesn't seem to have a
> good replacement for macros.  The closest equivalents are $Pre(Read),
> which I used in my solution, but they're not nearly as nice to work with.
> Can anyone think of an elegant solution?

  • Prev by Date: Re: problem writing debugging utility function
  • Next by Date: Re: printing problem with very simple application
  • Previous by thread: Re: problem writing debugging utility function
  • Next by thread: Re: problem writing debugging utility function