Files
org-notes/learning/programming-languages/common-lisp/common-lisp.org

55 lines
1.7 KiB
Org Mode

#+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]]
* Libraries to look into
- [[https://github.com/mmontone/ten/blob/master][Ten]] - templating library
- [[https://scymtym.github.io/esrap/][Esrap]] - Parse backwards