Fork me on GitHub
#clojure-spec
<
2018-06-20
>
Oliver George05:06:01

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.

Oliver George05:06:08

Re-running stest/instrument fixes this but would be annoying to do manually every time.

Oliver George05:06:54

How do you avoid losing instrumentation at the REPL?

sundarj07:06:47

@olivergeorge define a defn+instrument macro?

Oliver George08:06:01

An instrumenting version of defn would be perfect but ideally it'd be seamless.

gfredericks12:06:10

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

gfredericks12:06:09

related, what's the purpose of instrumentation? just for running tests, or for interactive development?

Oliver George12:06:44

Interactive development. Just starting on a re-natal mobile companion app to a clojurescript re-frame app.

Oliver George12:06:03

Figwheel has an "always reload" option for namespaces but a simple cursive repl is the case I was considering.

gfredericks12:06:59

I had the idea of monkeypatching defn, but I dunno how to accomplish that exactly in cljs

gfredericks12:06:24

(alter-var-root #'defn
 (fn [orig]
  (fn [& args]
   (let [form (apply orig args)]
    `(do ~form (st/instrument '~(ffirst (drop 2 args))))))))
something atrocious like that

Oliver George13:06:09

No immediate joy but I'll give it some more time later.

gfredericks14:06:07

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

noisesmith16:06:25

I assume that do was meant to be doto?

gfredericks16:06:10

I don't think so

gfredericks16:06:23

I mean it definitely wasn't, and I believe it's right that way

gfredericks16:06:54

I think st/instrument takes a symbol, not a var

noisesmith16:06:39

oh, so the intention is to no longer return the var but instead return whatever instrument returns?

noisesmith16:06:43

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

noisesmith16:06:35

anyway all I was getting at was that the original return value of defn was being dropped

gfredericks16:06:09

Oh good point. Need a let

gfredericks12:06:52

as long as it only runs in dev mode then it's not the worst thing in the world 🙂

Oliver George12:06:03

Thanks I'll give that a try

Oliver George13:06:05

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)

Oliver George13:06:13

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)