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.
fibonacci function shown below in a listener.
(defun fibonacci (m)
(let ((fib-n-1 1)
(fib-n-2 1)
(index 2))
(loop
(if (= index m) (return fib-n-1))
(incf index)
(psetq fib-n-1 (+ fib-n-1 fib-n-2)
fib-n-2 fib-n-1))))
(fibonacci "turtle")
= expects its arguments to be numbers, and displays several continuation options, so that you can try to find out how the problem arose. :bq at the debugger prompt to perform a quick backtrace. Notice that the problem is in the call tofibonacci. *%apply-interpreted-function in the backtrace occur becausefibonacci is being interpreted. fibonacci, rather than the string itself. (legnth "turtle")
fibonacci with the length of the string, but typed inlength 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. :a to return to the top level of the debugger. :v to display variable information about the current stack frame in the debugger. M : "turtle" INDEX : 2 FIB-N-2 : 1 FIB-N-1 : 1
m to be the length of the string "turtle", rather than the string itself. (setq m (length "turtle"))
m, you still need to handle the original error. :error to remind yourself of the original error condition you need to handle. nil from the call to=, which is the result that would have been obtained ifm had been correctly set. :c to invoke the continue restart, which in this case requires you to return a value to use. nil.