2

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 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I think printing is the right way to go. Ricky use the same ide as mine. Same position.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.