Debug - step through
In an earlier section you added a debugging line to a verb definition that allowed you to see the results of intermediate steps when the verb was run. Sometimes you need more powerful tools than that.
In recent versions of J the debug utilities are included, but if they are not you can always load 'debug' to load the debug utilities.
Open your script file cf.ijs and run it.
Let's execute centigrade, but with a stop on each line so that you can take a look at exactly what is going on.
dbss 'centigrade *:*'
The dbss (Set Stop) argument requests a stop before executing all, indicated by *:*, lines in centigrade.
dbr with an argument of 1 requests that the system suspend execution when an error or stop occurs. When a verb is suspended it is halted in mid execution. You can examine definitions, change definitions, and you can resume execution of the suspended verb.
centigrade 212 |stop | t1=.y-32 |centigrade
The error report (bars at the left margin) indicates execution stopped on line 0 of centigrade and shows the sentence from that line.
The execution of centigrade is suspended and the indent of six spaces, rather than three, indicates the suspension. The variable y is the argument.
The stop occurs before the line is executed, so t1 has not been defined and if you try to look at it you will get a value error.
Use dbrun to continue execution. It will run the current line, and because stops are set on all lines it will then stop on the next line.
dbrun '' |stop | t2=.t1*5 |centigrade t1 180 t1*5 900
centigrade is now stopped on line 1, and as you can see, you are able to check the value of local t1 that was defined in line 0. Step through the next lines and examine locals.
dbrun '' |stop | t3=.t2%9 |centigrade t2 900 t2%9 100 dbrun '' 100
You are no longer suspended in centigrade and you are back to the normal indent of three spaces.
Turn off the request for debug suspensions and reset to have no stops.
dbr 0 dbss ''
|Primer Index Hover to reveal titles - Click to access -|