MathGroup Archive 1990

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

Search the Archive


  • To: mathgroup at
  • Subject: debugPoint
  • From: uunet!SLCS.SLB.COM!macg (Bill Macgregor)
  • Date: Tue, 5 Jun 90 16:22:09 CDT

This message contains the definition of debugPoint, a small
Mathematica function that we find useful for debugging.  This
function may be obsoleted by new tracing features in Mma 2.0,
but meanwhile... 

The idea for debugPoint was mentioned by Elaine Kant at the 
Mathematica conference in January.  There were enough positive
comments at that meeting to justify distribution to the mailing

How it works

When debugPoint is called, it prints the String passed as its
first argument, and then it prints the values of any expressions 
given as its 2nd or subsequent arguments.  Values are printed
in the form 

    <unevaluated expression> == <evaluated expression>

so you can tell what is being printed.  debugPoint then enters
an interactive evaluation loop.  Any expression presented will
be evaluated and printed in the usual way, except the input
string "go" (without the quotes) which terminates the interaction
sequence.  Example:

  In[4]:= Block[{e},
            e = Expand[(x + y)^4];
            debugPoint["after Set[e, ...]", e];
  debugPoint:  after Set[e, ...]
            4      3        2  2        3    4
      e == y  + 4 y  x + 6 y  x  + 4 y x  + x
      debugIn:= x + x
      debugOut= 2 x
      debugIn:= go


The actions of debugPoint are controlled by two global symbols,
debugPrint and debugPause.  If either is True, debugPoint prints
the label when it is evaluated.  If debugPrint is True, debugPoint
prints the unevaluated == evaluated forms.  If debugPause is
True, debugPoint enters the interactive evaluation loop.

Hint for its use:  if you work with multiple packages, it is a
good idea to always include $Context in the debugPoint argument 

Definitions follow.

  - Bill MacGregor
    Schlumberger Laboratory for Computer Science


debugPrint = True;
debugPause = True;

debugPoint::usage = "debugPoint[s_String] prints the label s if 
debugPrint or debugPause is True, and pauses for interactive input 
if debugPause is True.  debugPoint[s_String, x__] also prints the 
unevaluated and evaluated forms of the arguments x, if debugPrint 
is True.";


SetAttributes[debugPoint, HoldAll];

debugPoint[s_:"(unlabelled)", x___] := Block[{e},
    If[TrueQ[debugPrint] || TrueQ[debugPause],
        Print["debugPoint:  ", s];
        Scan[Print["    ", 
                   StringJoin @@ 
                       Drop[Drop[Characters[ToString[InputForm[#]]] ,5], -1],
                   " == ",
            Map[Hold, Hold[x], 1]
        While[(e = InputString["    debugIn:= "]) != "go",
            Print["    debugOut= ", ToExpression[e]]

  • Prev by Date: Two quasi-bugs in Macintosh II Mathematica
  • Next by Date: mathematical relations
  • Previous by thread: Two quasi-bugs in Macintosh II Mathematica
  • Next by thread: mathematical relations