News for hackers. Stuff that matters.
Re:Data notation in Clojure by adrusi on Thursday July 01, 2021 @02:27PM (#27702605)
There are other advantages. I occasionally find myself using syntax-quote for refactoring. Let’s say I have a test like this:

    (let [cases [{:in [1 2 3] :out [2 4 6]}
                 ;; ...
                ]]
      (doseq [{:keys [in out]} cases]
        (is (= out (test-fn in)))))
If I want to inline the test cases, I can rewrite it like this

    (let [cases [{:in [1 2 3] :out [2 4 6]}
                 ;; ...
                ]]
      (map (fn [{:keys [in out]}]
             `(is (= ~out (test-fn ~in))))
           cases))
Then eval that in the repl and copy the result back into the test file. It’s a bit clunky because the repl output uses fully qualified symbols, but cleaning that up is usually faster that manually typing out the code it generates.

There are no comments on this comment yet.