This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-20
Channels
- # beginners (94)
- # boot (8)
- # cider (21)
- # cljs-dev (3)
- # cljsjs (5)
- # cljsrn (10)
- # clojure (167)
- # clojure-italy (4)
- # clojure-norway (1)
- # clojure-russia (9)
- # clojure-spec (25)
- # clojure-uk (29)
- # clojurescript (20)
- # cursive (12)
- # datomic (55)
- # emacs (10)
- # fulcro (16)
- # graphql (1)
- # hoplon (18)
- # lein-figwheel (30)
- # off-topic (259)
- # onyx (8)
- # other-languages (13)
- # re-frame (1)
- # reagent (62)
- # ring (8)
- # ring-swagger (28)
- # shadow-cljs (187)
- # spacemacs (15)
- # specter (2)
- # testing (12)
- # tools-deps (38)
I'm wondering how to avoid a REPL gotcha related to instrumentation. Since stest/instrument
wraps existing functions you effectively lose instrumentation by redefining a function with defn
at the REPL.
Re-running stest/instrument
fixes this but would be annoying to do manually every time.
How do you avoid losing instrumentation at the REPL?
@olivergeorge define a defn+instrument
macro?
An instrumenting version of defn would be perfect but ideally it'd be seamless.
what tooling are you using? I'm often editing the files and running the tools.namespace refresh
function, which means I can either have the call to instrument
at the bottom of a given namespace, or else use the callback hooks in refresh
related, what's the purpose of instrumentation? just for running tests, or for interactive development?
Interactive development. Just starting on a re-natal mobile companion app to a clojurescript re-frame app.
Figwheel has an "always reload" option for namespaces but a simple cursive repl is the case I was considering.
I had the idea of monkeypatching defn
, but I dunno how to accomplish that exactly in cljs
(alter-var-root #'defn
(fn [orig]
(fn [& args]
(let [form (apply orig args)]
`(do ~form (st/instrument '~(ffirst (drop 2 args))))))))
something atrocious like thatNo immediate joy but I'll give it some more time later.
you'd have to somehow get that to run in the cljs compiler process
also I realized it's possible that defn
isn't even a macro in cljs; it could be a special form
I assume that do was meant to be doto?
I don't think so
I mean it definitely wasn't, and I believe it's right that way
I think st/instrument
takes a symbol, not a var
oh, so the intention is to no longer return the var but instead return whatever instrument returns?
I am probably weird for doing this, but I have a repl workflow where I count on being able to call load-file
and then (*1)
to call the last var in the file
anyway all I was getting at was that the original return value of defn was being dropped
Oh good point. Need a let
as long as it only runs in dev mode then it's not the worst thing in the world 🙂
Thanks I'll give that a try
I might be able to do something similar via a custom command in cursive. Looks like I can send something like this to the repl with a hotkey (untested):
~top-level-form
(instrument ~current-var)
Another approach would be using a patched version of clojurescript for development. (Must try and see how hard that is now that deps.edn does github shas)