How to understand atom updates in real time

Hey all, I’m working on my first to-do list project. My first “head scratch” :thinking: question is, why does it seem that I need to “reset” my to-do list vector to be empty in order to get the expected print out of “empty list” followed by “list with one item” ?

Please see my code example here: autofocus-clj-ver-1/core.clj at main · avidrucker/autofocus-clj-ver-1 · GitHub

(reset-list) ;; note: comment this out to see strange behavior
(println (stringify-list)) ;; should print out empty
(add-item-to-list example-item)
(println (stringify-list)) ;; should print out with only 1 item

The atom preserves state between calls if the JVM process stays running. Are you running this multiple times in a row, and thus affecting each test run with those prior?

1 Like

Yep @dave.liepmann I am running multiple times in a row :sweat_smile: Restarting the REPL gives the expected output :+1::slightly_smiling_face: Thank you for teaching me that about atoms preserving state between calls 🙇‍♂

1 Like

It seems I can’t update my original post…

For posterity’s sake, here is the link to the code at the time it was sourced above, since I have updated the repo since then.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.