Hacker News new | past | comments | ask | show | jobs | submit login

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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: