如何调试IntelliJ中的Clojure文件? [英] How to debug a Clojure file in IntelliJ?

查看:136
本文介绍了如何调试IntelliJ中的Clojure文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不能在第5行设置断点,第5行包含 [x]

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

IntelliJ不会让我这样做。我使用了不同的插件,例如 La Clojure Cursive 。两者都停在第3行,而不是第5行。

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.

那么,人们怎么进入Clojure的代码呢?

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])


推荐答案

首先,按照惯例,所有尾括号都在同一行, p>

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])

其次,当你使用composable函数时,很容易插入一个println并运行/测试这个函数,因为它是透明的。我只是一个Clojure爱好者,但我通常调试与printlns和单元测试。使用断点不是真的可靠。

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).

这篇关于如何调试IntelliJ中的Clojure文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆