Notes 6/7/23

This commit is contained in:
2023-06-07 22:20:32 -04:00
parent b1e8dea50e
commit 47dc5e09ad
3 changed files with 93 additions and 97 deletions

49
common-lisp.org Normal file
View File

@@ -0,0 +1,49 @@
#+TITLE: Common Lisp
#+AUTHOR: Adam Mohammed
* Blogs
- [[https://malisper.me][malisper.me]]
* Debugging
Add this to set SBCL to have debug mode enabled.
#+begin_src lisp
CL-USER> (declaim (optimize (debug 3)))
NIL
#+end_src
This is broken because of the divide by zero:
#+begin_src lisp
(defun fib (n)
(if (<= 0 n 1)
(/ 1 0)
(+ (fib (- n 1))
(fib (- n 2)))))
#+end_src
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!
#+begin_src lisp
(defun fib (n)
(break)
(if (<= 0 n 1)
(/ 1 0)
(+ (fib (- n 1))
(fib (- n 2)))))
#+end_src
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.
+ References:
- [[https://malisper.me/debugging-lisp-part-1-recompilation/][Recompilation]]
- [[https://malisper.me/debugging-lisp-part-2-inspecting/][Inspecting]]
- [[https://malisper.me/debugging-lisp-part-3-redefining-classes/][Redefining Classes]]
- [[https://malisper.me/debugging-lisp-part-4-restarts/][Restarts]]
- [[https://malisper.me/debugging-lisp-part-5-miscellaneous/][tricks]]