Message Boards Message Boards

0
|
4294 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Stopping Mathematica to look at variables

Posted 3 years ago

In the course of processing input data and metadata from a hypercard stack, a function uses 20 - 25 variables (either string or integers) So I have things like

If [StringQ [someVariable], Null, showXCardVariables ]
If [IntegerQ [someOtherVariable], Null, showXCardVariables [ ] ]

showXCardVariables [ ] currently looks like this 

 showXCardVariables [ ] := (  
  Print [ "NumCardsS = " ] Print [ numCardsS ]
   Print [ "NumCardsI = " ] Print [ numCardsI ]
    Print [ "gln =  "] Print [gln ]
      Print [ "cardEntryGln = "] Print [ cardEntryGln ]
        Print [ "lcln = "] Print [ lcln ]
         Print [ "line1 = " ] Print [ line1]
   Print [ "cardName = " ] Print [ cardName ] 
   Print [  "line2 = " ] Print [ line2 ]
   Print [  "cardID = " ] Print [ cardID ]
    Print  [ "xRefTile = " ] Print [ xRefTitle ]
      Print [ "numButtonsS = " ] Print [ numButtonsS ] 
     Print [ " numButtonsI = " ] Print [ numButtonsI ] 
   Print [ " buttonDataPointer = " ] Print [ buttonDataPointer ]
     Print [ "numTopicsS = " ]  Print [ numTopicsS ]
     Print [ "numTopicsI = " ] Print [ numTopicsI ]
    Print [ " topicDataPointer = " ] Print [ topicDataPointer ]
     Print [ " numlinesS = " ] Print [ numLinesS ]
       Print [ " numLinesI = " ] Print [ numLinesI ]
       Print [ " textDataPointer = " ] Print [ textDataPointer ]
         Print [ " lastLine = " ]  Print [ lastLine ]
   )

My problem is getting showXCardVariables to stop when it has been called, and not return, until I tell it to, so I can look at what went wrong. I can't find a way to do this.

POSTED BY: Lewis Robinson
2 Replies
Posted 3 years ago
POSTED BY: Lewis Robinson
Posted 3 years ago

Not clear how you are going to "look at what went wrong" by stopping a function that just prints values. Isn't it too late at that point since the values have already been computed? Some suggestions:

Add ; after each of the Print, without that it is a single expression that is the product of the result of evaluating Print, which is always Null.

Rather than Print, save the computed values in an Association

result = <||>;
(* some computation *)
result["NumCardsS"] = numCardsS;
(* some computation *)
result["NumCardsI"] = numCardsI;
(* ... *)
result

Use the debugger. At a point in the code where you want to stop evaluation add

Assert[False]

From the Evaluation menu select Debugger, in the palette make sure "Break at Asserts" is checked. Evaluate the outer expression, when the Assert is reached the debugger will pause execution and you can look at the values of symbols, step through the code, ... from the debugger palette.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract