by lispm · 3y ago · 0 comments
* (defun foo (x)
(declare (optimize (debug 3)))
(let ((n 10))
(break)
(* x n)))
FOO
* (foo 3) ; calling foo
(foo 3)
We get a break repl: debugger invoked on a SIMPLE-CONDITION
restarts (invokable by number or by possibly-abbreviated name):
0: [CONTINUE] Return from BREAK.
1: [ABORT ] Exit debugger, returning to top level.
(FOO 3)
source: (BREAK)
Let's change the local variable N of the running function FOO: 0] (setf n 12)
(setf n 12)
12
Return from the break: 0] 0 ; restart 0
0
36
Note that you may want to reduce the optimization level of SBCL, since by default everything is compiled, and its optimizing compiler might get rid of a few of the variables during compilation. For example the compiler might detect that N's literal value 10 is not changed in the function and replace the variable access to N with the compile-time value. That's why I used the DEBUG quality 3 (highest) to tell the compiler to not optimize the code.How? I ran the same function, brought up the debugger, if I try to type something emacs says the buffer is read-only. Was I supposed to push e first?