This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-05
Channels
- # announcements (2)
- # beginners (44)
- # calva (7)
- # cider (8)
- # cljs-dev (2)
- # clojure (131)
- # clojure-serbia (2)
- # clojure-spec (3)
- # clojure-uk (56)
- # clojurescript (27)
- # cursive (7)
- # datomic (6)
- # fulcro (25)
- # jobs (3)
- # klipse (3)
- # leiningen (2)
- # off-topic (8)
- # overtone (2)
- # pathom (2)
- # portkey (2)
- # re-frame (2)
- # reagent (10)
- # shadow-cljs (44)
- # spacemacs (1)
- # tools-deps (6)
- # uncomplicate (2)
Could one implement a quick-and-dirty debugger with the following approach?
(defn debugger []
(nrepl.server/start-server :port 7888) ;; this should be a blocking call. The nREPL server remains open until the first client that connects to it tells it to quit
)
So, I place a (debugger)
call anywhere, execution stops there, and I can lein repl :connect localhost:7888
from a secondary terminal
Sounds possible? Anyone doing that already?
Would be particularly interesting if the spawned nrepl captured the local bindings of the parentThis guy had the same idea and seemed to have some luck... first answer is useful https://stackoverflow.com/questions/49599694/how-to-see-clojure-local-variables-in-local-repl
This is being useful as well! https://github.com/GeorgeJahad/debug-repl/blob/master/src/alex_and_georges/debug_repl.clj
I use this:
(defn contextual-eval [ctx expr]
(eval
`(let [[email protected](mapcat (fn [[k v]] [k `'~v]) ctx)]
~expr)))
(defn readr [prompt exit-code]
(let [input (clojure.main/repl-read prompt exit-code)]
(if (= input :q)
exit-code
input)))
(defmacro local-context []
(let [symbols (keys &env)]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(defmacro break
":q to exit"
[]
`(clojure.main/repl
:prompt #(print "debug => ")
:read readr
:eval (partial contextual-eval (local-context))))
Believe I stole that from somewhere, but I apparently didn't make a note of where. Works fine for me 🙂
Looks like I stole it from Joy of Clojure, as cited here: https://gist.github.com/leobm/6061734