Fork me on GitHub
#calva
<
2022-12-11
>
James Pratt03:12:46

Is it possible to step through code that includes an infinite lazy sequence without crashing the debugger??

clj꞉rich4clojure.hard.problem-073꞉> 
#dbg
(defn tic-tac-toe [board]
  (some identity (flatten
                  (for [winner [:x :0]]
                    (or (map (partial row-winner winner)
                             (take 2 (iterate flip-board board)))
                        (diagonal-winner winner board))))))
Debugger is not liking that (iterate flip-board board) and the REPL stops responding.

😆 1
bringe04:12:34

I’m not aware of an issue with this, but I do know the breakpoint finding logic for where to place the cursor is not perfect. It’s likely that there’s an issue in the function for finding the breakpoint. https://github.com/BetterThanTomorrow/calva/blob/5e124de90c70770a080d766351703c631c3699f6/src/debugger/util.ts#L20 If you’re interested in digging in, you can try running Calva in development mode and setting a breakpoint in that function and seeing if there’s an issue there. A GH issue is welcome too, and then if you or someone else who uses the debugger wants to look more into later, I’m happy to help and review a PR.

James Pratt18:12:08

"I’m not aware of an issue with this" Yeah, I guess this behaviour is what you would expect. If you step through code that includes lazy infinite sequences and the debugger evaluates the whole sequence to display the value then you are going to get an error were as the code is valid.

James Pratt18:12:00

Just to whittle down an example to essentials.

#dbg
(defn something [] (take 5 (repeat 1)))

(comment (something)
         ;; => Execution error (OutOfMemoryError) at java.util.Arrays/copyOf (Arrays.java:3537).
         ;;    Java heap space
)
Ah, cool. I found the entry in the manual about this> https://calva.io/debugger/#debugger-hangs-when-stepping-over-infinite-seqs

bringe18:12:39

Oh, sorry, I was not thinking correctly about it before.

🙌 1
bringe18:12:14

I may have written that entry. 😆

😀 1
James Pratt18:12:49

Cursive doesn't display values of un-realized lazy sequences I think

James Pratt18:12:17

I like the approach of being able to say how much of it you want to see

👍 1
James Pratt18:12:09

as Calva allows

calva 1