debuggingclojureinlineread-eval-print-loopvscode-calva

Clojure: capture runtime value of function arg, to use in REPL


Problem

My web front-end calls back-end queries with complex arguments. During development, to avoid time-consuming manual replication of those arguments, I want to capture their values in Vars, which can be used in REPL.

Research

This article shows that inline def is a suitable solution, but I couldn't make it work. After a call from the front-end happened, the Var remained unbound.

I launched the backend with REPL through VS Code + Calva, with the following code:

(defn get-analytics-by-category [params]
  (def params params)
  ...)

And here's the evaluation of the Var in the REPL:

#object[clojure.lang.Var$Unbound 0x1298f89e "Unbound: #'urbest.db.queries/params"]

Question

Why the code above didn't bound value of the argument to the Var? Is there another solution?


Solution

  • Nowadays I use Playback.

    It captures func args, local variables and more, with just #>> macro added in the right place. Also includes function replay.

    The values that you traces are placed into Portal, where even large data structures can be easily browsed and reused.