BreakpointsA breakpoint is an an intentional pausing place in a program for debugging purpose. It is a means of getting information about a program during its execution. During the interruption, you can check whether the program is functioning as expected. In Smojo, we use the word
BPto place a breakpoint in the code.
: addition bp + bp cr "The sum is " . . cr bp ; 5 2 addition --breakpoint: ADDITION -- <2> 5 2 --breakpoint: ADDITION -- <1> 7 The sum is 7 --breakpoint: ADDITION -- <0> ok
Question 1Run the
ADDITIONprogram. Can you explain what happens at the three different breakpoints?
bpis run, the state of the stack at that time is shown. At the first brakpoint,
2are on the stack. At the second breakpoint, i.e., after
+, the two numbers are consumed and their sum
7is pushed onto the stack. At the third breakpoint, the number
7is popped and printed so there is nothing on the stack.