This section presents a short interactive debugging session. It starts by defining a routine to calculate Fibonacci Numbers, and then erroneously calls it with a string.
fibonaccifunction shown below in a listener.
(defun fibonacci (m)
(let ((fib-n-1 1)
(if (= index m) (return fib-n-1))
(psetq fib-n-1 (+ fib-n-1 fib-n-2)
The system generates an error, since
expects its arguments to be numbers, and displays several continuation options, so that you can try to find out how the problem arose.
:bqat the debugger prompt to perform a quick backtrace. Notice that the problem is in the call to
Note that the calls to
in the backtrace occur because
is being interpreted.
You should have passed the length of the string as an argument to
, rather than the string itself.
You intended to call
with the length of the string, but typed in
incorrectly. This takes you into the second level of the debugger. Note that the continuation options from your entry into the top level of the debugger are still displayed, and are listed after the new options. You can select any of these options.
:ato return to the top level of the debugger.
:vto display variable information about the current stack frame in the debugger.
The following output is displayed:
M : "turtle"
INDEX : 2
FIB-N-2 : 1
FIB-N-1 : 1
You need to set the value of the variable
to be the length of the string "turtle", rather than the string itself.
(setq m (length "turtle"))
In order to get the original computation to resume using the new value of
, you still need to handle the original error.
:errorto remind yourself of the original error condition you need to handle.
You can handle this error by returning
from the call to
, which is the result that would have been obtained if
had been correctly set.
:cto invoke the continue restart, which in this case requires you to return a value to use.
This causes execution to continue as desired, and you can obtain the final result with no further problems.