I'm trying to run this code:
(defparameter *digits-string* (uiop:read-file-string "day08.txt"))
(defparameter shape '(25 6))
(defun read-file-into-layers (filepath layer-w layer-h)
(with-open-file (stream filepath)
(do ((char (read-char stream) (read-char stream))
(layer-size (* layer-w layer-h))
(layers nil)
(layer nil)
(i nil))
((not (digit-char-p char)) layers)
(when (null layer) (setf layer (make-array layer-size)
i 0))
(setf (aref layer i) (digit-char-p char))
(incf i)
(when (= i layer-size) (progn (push layers layer)
(setf layer nil
i 0))))))
(https://github.com/AlbertoEAF/advent_of_code_2019/blob/d0a331157cbb3f37a16ae92f3cc2c56a35b3e00e/common-lisp/day08.lisp#L14-L28 + day08.txt for https://adventofcode.com/2019/day/8)
which is returning nil, not sure why (the file contains a single line with 15k digits and a newline at the end).
I'm trying to debug with:
;; 1) Set maximum debug level
(declaim (optimize (speed 0) (space 0) (debug 3)))
;; 2) Recompile the full module + C-u C-c C-c on that function (don't know if that last part is needed)
;; 3) step:
(step (READ-file-into-layers "day08.txt" 25 6))
I still don't see almost any variable and stepping only stops at (read-char stream)
and (incf i)
, nothing else? And almost no variables are defined!
Also, if I press "e" to evaluate some expressions, even though at times some variables don't appear on the stacktrace, in this case it reports that they're not defined at all.
Any ideas of why the debugger is having this strange behaviour? Or is it just my code that is completely broken? Still, the debugger would be most helpful in this case if it worked :)
It might be that your compiler is too smart. When you take a close look, then because of the inversed push
form, you only ever set layer
and layers
to nil
. At one point, layer
becomes (nil)
only to be reverted to nil
directly after that. If all these no-ops get thrown out, not much is left to step.
You could try to glean whether this is the case by disassembling your compiled function using disassemble
.