Download Maple Introductory Programming Guide

Transcript
310
•
Chapter 8: Debugging and Efficiency
where numLevels
To illustrate these commands, consider the following example. The
procedure check calls the sumn procedure from the previous example.
> check := proc(i) local p, a, b;
>
p := ithprime(i);
>
a := sumn(p);
>
b := p*(p+1)/2;
>
evalb( a=b );
> end proc:
There is a (conditional) breakpoint in sumn.
> showstat(sumn);
sumn := proc(n)
local i, sum;
1
sum := 0;
2
for i to n do
3?
sum := sum+i
end do
end proc
When check calls sumn, the breakpoint invokes the debugger.
> check(9);
10
sumn:
3?
sum := sum+i
The where debugger command reveals that:
• check was invoked from the top-level with argument 9,
• check called sumn with argument 23, and
• execution stopped at statement number 3 in sumn.
DBG > where