Files

1.7 KiB

Common Lisp

Blogs

Debugging

Add this to set SBCL to have debug mode enabled.

CL-USER> (declaim (optimize (debug 3)))
NIL

This is broken because of the divide by zero:

  (defun fib (n)
    (if (<= 0 n 1)
	(/ 1 0)
	(+ (fib (- n 1))
	   (fib (- n 2)))))

Running the above puts us in the debugger once we hit the base case, but we can edit the function definition by adding (break) and then press r on the frame we wish to restart. Once we fix the code we can restart stepping and the issue can be fixed live!

  (defun fib (n)
    (break)
    (if (<= 0 n 1)
	(/ 1 0)
	(+ (fib (- n 1))
	   (fib (- n 2)))))

You can toggle C-c M-t (slime trace dialog) on a funcion and then invoke it and then view the results with C-c T.

update-instance-for-redefined-class is handy for defining migration behavior when you need to redefine a class.

Restarts can be a handy tool where throw/catch would normally be used. Restarts allow for a user-defined failure functionality to be selected while still maintaining control in the function which caused the error.

Libraries to look into

  • Ten - templating library
  • Esrap - Parse backwards