cider

Quentin Le Guennec 2024-11-22T13:34:15.199949Z

Is there a way to save runtime values in clojurescript, to inspect them at the repl ?

mitchelkuijpers 2024-11-22T14:09:54.490819Z

I do this by adding a def inside the function I am debugging:

(defn my-fn [x y]
  (def _args [x y])
  ....)

(comment
  _args => [1 2]
)

mitchelkuijpers 2024-11-22T14:11:31.031079Z

So I first add a def with what I want to inspect and then add a comment block below that and then eval the def. I always start these names with a underscore to make sure I don't define stuff that is used in functions

Quentin Le Guennec 2024-11-22T14:16:49.432829Z

cool trick, quite simple, thanks.

2024-11-22T14:25:40.665719Z

for debugging there is also http://www.flow-storm.org/ and https://github.com/flow-storm/cider-storm which allows to define any value (or all of them) to work with them at the repl and much more

2024-11-22T14:28:31.317359Z

one problem with using def like that is if my-fn is called multiple times as part of the execution you will only get the last one. Same if you need to capture things inside any kind of "looping", like map, filter, etc

mitchelkuijpers 2024-11-22T15:07:24.840049Z

And totally agree for more powerfull stuff look at flowstorm

Arek 2024-11-29T14:19:43.718399Z

I also use inline defs a lot, but another cool trick is to console.log something and then in console right click on the logged object and click Store as Global Variable. Then you can access it in the REPL with js/temp0

Arek 2024-11-29T14:20:41.754769Z

And if you need something more advanced there's https://github.com/AbhinavOmprakash/snitch But as far as I know the latest version doesn't work with ClojureScript so you need to use an older one