next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: step

step -- step by single lines in the debugger

Synopsis

Description

One useful way to debug code suspected of being in error is to insert an explicit error message, such as error "debug me", and start stepping from there, as in the following demonstration.

i1 : load "Macaulay2Doc/demo2.m2"
i2 : code f

o2 = /usr/share/Macaulay2/Macaulay2Doc/demo2.m2:6:7-12:13: --source code:
     f = t -> (
          x := 1;
          error "debug me";
          y := t+1;
          z := 1/t;
          w := x+t;
          )
i3 : f 0
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:8:6:(3):[1]: error: debug me
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:8:6:(3):[1]: --entering debugger (type help to see debugger commands)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:8:6-8:6: --source code:
     error "debug me";
ii4 : return
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:8:(3):[1]: --stepping limit reached
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:8:(3):[1]: --entering debugger (type help to see debugger commands)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:8-9:13: --source code:
     y := t+1;
ii5 : disassemble current

oo5 = (local-assign 2 0 (2-OP + (fetch 0 0) 1))
ii6 : step(-3)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:8:(3):[1]: --evaluating: (local-assign 2 0 (2-OP + (fetch 0 0) 1))
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:12:(3):[1]: --evaluating: (2-OP + (fetch 0 0) 1)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:11:(3):[1]: --evaluating: (fetch 0 0)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:13:(3):[1]: --stepping limit reached
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:13:(3):[1]: --entering debugger (type help to see debugger commands)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:9:13-9:13: --source code:
     y := t+1;
ii7 : step
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:10:8:(3):[1]: --stepping limit reached
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:10:8:(3):[1]: --entering debugger (type help to see debugger commands)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:10:8-10:13: --source code:
     z := 1/t;
ii8 : step
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:10:12:(3):[1]: error: division by zero
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:10:12:(3):[1]: --entering debugger (type help to see debugger commands)
/usr/share/Macaulay2/Macaulay2Doc/demo2.m2:10:11-10:13: --source code:
     z := 1/t;
ii9 : t

oo9 = 0

See also

For the programmer

The object step is a keyword.