Message Boards Message Boards

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

Stopping Mathematica to look at variables

Posted 2 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 2 years ago

Rohit:

That's marvelous -- I didn't know we had a debugger. I told you I was a Mathematica Neophyte. Wolfram's Mathematica 5 had very little on it.

The reason for looking at the variables, is ****not**** because I'm worried about the correctness or incorrectness of what I'm writing in Mathematica (as I can check each line). What I'm worried about is the correctness of Hypercard programs I wrote to create text files of data and metadata. A second concern is that it possible that some of the Hypercard stacks and cards are themselves corrupted. If the data and metadata isn't doing what my Mathematica program thinks it should be doing, I want to know in which Hypercard card it occurred in and why the Hypercard program did what it did.

Here's a small sample of the current program. You can see all the checks.

As always thanks for your help.

In[108]:= numTopicsS = data [[  lcln]]

Out[108]= "1 "

In[109]:= If [ StringQ[ numTopicsS ], Null, showXCardVariables [] ]

In[112]:= numTopicsI = ToExpression [ numTopicsS ]

Out[112]= 1

If [ IntegerQ[ numTopicsI], Null, showXCardVariables [] ]


Out[57]= True

In[115]:= lcln = inc [ lcln ]

11   

In[116]:= topicDataPointer = lcln  

Out[116]= 11

In[117]:= If [ IntegerQ[ topicDataPointer], Null, 
 showXCardVariables [] ]


In[120]:= lcln = lcln + numTopicsI

12 

In[121]:= numLinesS = 
 data [[ 
  lcln  ]] (* need to save as a string, to use as a header in the \
card written out *)

Out[121]= "2 "

In[122]:= If [StringQ [ numLinesS], Null, showXCardVariables ]

In[125]:= 
numLinesI = ToExpression [ numLinesS ]

In[126]:= If [ IntegerQ[ numLinesI], Null, showXCardVariables [] ]


In[129]:= lcln = inc [ lcln ]

13 ** ** ** **



In[130]:= textDataPointer = lcln

In[131]:= If [ IntegerQ [ textDataPointer ], Null, 
 showXCardVariables [] ]

In[134]:= 13
lcln  = lcln + numLinesI

Out[135]= 15

In[136]:= lastLine = data [[ lcln]]

Out[136]= "End  card \"X2383901\" "
POSTED BY: Lewis Robinson
Posted 2 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