How to debug a Clojure file in IntelliJ?

落爺英雄遲暮 提交于 2020-01-04 21:39:12

问题


No breakpoint can be set on line 5, which contains [x].

IntelliJ won't let me do so. I used different plugin, such as La Clojure and Cursive. Both stop at line 3 rather than line 5.

So, how people step into the code in Clojure?

Is there any syntax suggestion or maybe tool to help with?

(defn flattenlist
  ([x & more]
    (concat (if (vector? x)
              (apply flattenlist x)
              [x]
            )
            (if (= more nil)
              nil
              (apply flattenlist more))))
  )
(flattenlist [[1 [[2]]] 3 [4 5] 6])

回答1:


First, by convention, all trailing parentheses are on the same line, something like this:

(defn flattenlist
  ([x & more]
   (println x)
   (concat (if (vector? x)
             (apply flattenlist x)
             [x])
           (if (= more nil)
             nil
             (apply flattenlist more)))))

(flattenlist [[1 [[2]]] 3 [4 5] 6])

Secondly, when you use composable functions, it is easy to insert a println and run/test just that function because it is referentially transparent. I am only a Clojure hobbyist, but I typically debug with printlns and unit tests. Using breakpoints isn't really that reliable.

If you really want something similar to setting a breakpoint, you can try using this debugging macro (not mine).



来源:https://stackoverflow.com/questions/25009122/how-to-debug-a-clojure-file-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!